From 6c41d7afdec77a106e625562e5bdf62bb1ef17a8 Mon Sep 17 00:00:00 2001 From: Stephan Auerhahn Date: Tue, 13 Dec 2022 11:24:22 -0800 Subject: [PATCH] Add dockerfile for bot and build/publish actions --- .github/workflows/docker/backend.yaml | 14 +++++++ .github/workflows/docker/bot.yaml | 14 +++++++ .github/workflows/docker/build.yaml | 53 +++++++++++++++++++++++++++ bot/Dockerfile | 7 ++++ 4 files changed, 88 insertions(+) create mode 100644 .github/workflows/docker/backend.yaml create mode 100644 .github/workflows/docker/bot.yaml create mode 100644 .github/workflows/docker/build.yaml create mode 100644 bot/Dockerfile diff --git a/.github/workflows/docker/backend.yaml b/.github/workflows/docker/backend.yaml new file mode 100644 index 00000000..b054e819 --- /dev/null +++ b/.github/workflows/docker/backend.yaml @@ -0,0 +1,14 @@ +name: (Backend) Publish Docker Image + +on: + push: + paths: + - 'backend/**' + +jobs: + build: + uses: ./.github/workflows/docker/build.yaml + with: + image-name: backend + folder: backend + build-args: "" \ No newline at end of file diff --git a/.github/workflows/docker/bot.yaml b/.github/workflows/docker/bot.yaml new file mode 100644 index 00000000..a0ec3a5f --- /dev/null +++ b/.github/workflows/docker/bot.yaml @@ -0,0 +1,14 @@ +name: (Bot) Publish Docker Image + +on: + push: + paths: + - 'bot/**' + +jobs: + build: + uses: ./.github/workflows/docker/build.yaml + with: + image-name: bot + folder: bot + build-args: "" \ No newline at end of file diff --git a/.github/workflows/docker/build.yaml b/.github/workflows/docker/build.yaml new file mode 100644 index 00000000..8ba7bd26 --- /dev/null +++ b/.github/workflows/docker/build.yaml @@ -0,0 +1,53 @@ +name: Build + +on: + workflow_call: + inputs: + folder: + required: true + type: string + image-name: + required: true + type: string + build-args: + required: false + type: string + +jobs: + build: + name: Build Images + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2.2.1 + - name: Login to container registry + uses: docker/login-action@v2.1.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Get base registry + run: | + echo "REGISTRY=ghcr.io/${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV + - name: Set tag prefix + if: github.ref_name != 'main' + run: | + echo "TAG_PREFIX=${{ github.ref_name }}-" >> $GITHUB_ENV + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4.1.1 + with: + images: ${{ env.REGISTRY }}/${{ inputs.image-name }} + tags: | + type=sha,prefix=${{ env.TAG_PREFIX }},format=short + - name: Build and push Docker image + uses: docker/build-push-action@v3.2.0 + with: + context: ${{ inputs.folder }} + build-args: ${{ inputs.build-args }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ inputs.image-name }}:buildcache + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ inputs.image-name }}:buildcache,mode=max diff --git a/bot/Dockerfile b/bot/Dockerfile new file mode 100644 index 00000000..9cff3dc2 --- /dev/null +++ b/bot/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.10-slim-bullseye +RUN mkdir /app +ADD requirements.txt /app/requirements.txt +WORKDIR /app +RUN pip install -r requirements.txt +ADD . /app +CMD ["python", "bot.py"] \ No newline at end of file