Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker: Add support for Docker and github workflow #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Docker Image CI

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master

# Publish `v1.2.3` tags as releases.
tags:
- v*

# Run tests for any PRs.
pull_request:

env:
# TODO: Change variable to your image's name.
IMAGE_NAME: ti-processor-docs-build

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
docker-build-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Build Test container
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build --build-arg BASE_DISTRO=debian:stable-slim --build-arg USER_UID=1000 . --file Dockerfile
fi

# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push-docker-container:
# Ensure test job passes before pushing image.
needs: docker-build-test

runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v3

- name: Build the deployment container
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build --build-arg BASE_DISTRO=debian:stable-slim --build-arg USER_UID=1000 . --file Dockerfile
fi

- name: Log into GitHub Container Registry
run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME

# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')

# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')

# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')

# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest

echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION

docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARG BASE_DISTRO=debian:stable-slim
FROM $BASE_DISTRO

ARG USER_UID=1000

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
python3-sphinx python3-pip \
&& echo "**** cleanup ****" \
&& apt-get autoremove \
&& apt-get clean \
&& rm -rf \
/tmp/* \
/var/lib/apt/lists/* \
/var/tmp/* \
/var/log/*

RUN --mount=type=bind,source=requirements.txt,target=/tmp/requirements.txt \
python3 -m pip install --root-user-action=ignore --break-system-packages --upgrade pip setuptools && \
python3 -m pip install --root-user-action=ignore --break-system-packages -r /tmp/requirements.txt

# Publish the source repository
LABEL org.opencontainers.image.source https://github.com/TexasInstruments/processor-sdk-doc

RUN echo "**** create user and make our folders ****" \
&& useradd -u $USER_UID -U -d /config -s /bin/false user \
&& usermod -G users user \
&& mkdir /workdir && chown user:user /workdir \
&& mkdir /config && chown user:user /config

ENTRYPOINT ["/init"]
CMD ["/usr/bin/bash"]
VOLUME /workdir
WORKDIR /workdir