From 16e32f57d8ce350ea0d656614963fcf659490dc8 Mon Sep 17 00:00:00 2001 From: Philipp Grathwohl Date: Sat, 27 Nov 2021 15:21:05 +0100 Subject: [PATCH 1/2] Update docker file to install craftbeerpi Also install cbpi-ui from avollkopf repository. --- Dockerfile | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4252cd3..b973b7b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,43 @@ -FROM python:3.5.6-stretch +FROM alpine:latest as download +RUN apk --no-cache add curl && mkdir /downloads +# Download installation files +RUN curl https://github.com/avollkopf/craftbeerpi4-ui/archive/main.zip -L -o ./downloads/cbpi-ui.zip -WORKDIR /usr/src/app +FROM python:3.7-slim -COPY dist/cbpi-0.0.1.tar.gz ./ -RUN pip install cbpi-0.0.1.tar.gz --no-cache-dir +# Install dependencies +RUN apt-get update \ + && apt-get upgrade -y +RUN apt-get install --no-install-recommends -y \ + libatlas-base-dev \ + libffi-dev \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* -COPY . . +RUN python -m pip install --upgrade pip setuptools wheel -EXPOSE 8080 +WORKDIR /cbpi +# Create non-root user working directory +RUN groupadd -g 1000 -r craftbeerpi \ + && useradd -u 1000 -r -s /bin/false -g craftbeerpi craftbeerpi \ + && chown craftbeerpi:craftbeerpi /cbpi -CMD [ "cbpi" ] +# Install craftbeerpi from source +COPY . /cbpi-src +RUN pip3 install --no-cache-dir /cbpi-src +# Install craftbeerpi-ui +COPY --from=download /downloads /downloads +RUN pip3 install --no-cache-dir /downloads/cbpi-ui.zip +# Clean up installation files +RUN rm -rf /downloads /cbpi-src + +USER craftbeerpi + +RUN cbpi setup + +EXPOSE 8000 + +# Start cbpi +CMD ["cbpi", "start"] \ No newline at end of file From ea9b4bb9b97b26b84d78177656bc8d0b21bbb3c9 Mon Sep 17 00:00:00 2001 From: Philipp Grathwohl Date: Sat, 27 Nov 2021 16:14:14 +0100 Subject: [PATCH 2/2] Add github action for creating a docker image When building the master (or main) branch, create docker image that uses the tag 'latest' and a that that consists of the version number read from the __init__.py file. Use label 'dev' for all other builds. --- .github/workflows/build.yml | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1970a08 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,66 @@ +name: 'Build Docker Image' + +on: + push: + branches: + - main + - master + - development + +env: + image-name: ghcr.io/${{ github.repository_owner }}/craftbeerpi4 + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Prepare docker image and tag names + id: prep + run: | + + if [[ $GITHUB_REF_NAME == master ]] || [[ $GITHUB_REF_NAME == main ]]; then + # when building master/main use :latest tag and the version number + # from the cbpi/__init__.py file + VERSION=$(grep -o -E "(([0-9]{1,2}[.]?){3}[0-9]+)" cbpi/__init__.py) + TAGS="${{ env.image-name }}:latest,${{ env.image-name }}:v${VERSION}" + else + # otherwise just use :dev tag + TAGS="${{ env.image-name }}:dev" + fi + + # Set output parameters. + echo ::set-output name=tags::${TAGS} + + - name: Set up QEMU + uses: docker/setup-qemu-action@master + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@master + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build + uses: docker/build-push-action@v2 + with: + builder: ${{ steps.buildx.outputs.name }} + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.prep.outputs.tags }} + labels: | + org.opencontainers.image.title=${{ github.event.repository.name }} + org.opencontainers.image.description=${{ github.event.repository.description }} + org.opencontainers.image.url=${{ github.event.repository.html_url }} + org.opencontainers.image.revision=${{ github.sha }}