From 62c0ec90f7943d28f0707af837b40ca805604115 Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Fri, 9 Feb 2024 17:06:09 -0400 Subject: [PATCH] Get docker containers building (PP-882) (#10) * Get docker containers building * Fix caching * Fix caching again * Fix error in docker build --- .dockerignore | 3 - .github/workflows/build.yml | 109 ++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.dockerignore b/.dockerignore index ec941aa..7937a98 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,9 +4,6 @@ # Temp files *~ -# Readmes -**/*.md - # Tests tests/ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..787249c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,109 @@ +name: Docker build + +on: + - push + +concurrency: + group: docker-${{ github.ref_name }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout the code + uses: actions/checkout@v4 + with: + persist-credentials: false + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: Install Poetry + uses: ThePalaceProject/circulation/.github/actions/poetry@main + with: + version: "1.7.1" + + - name: Setup Dunamai + run: | + poetry install --only ci + env: + POETRY_VIRTUALENVS_CREATE: false + + - name: Create version file + run: | + echo "__version__ = '$(dunamai from git --style semver)'" >> virtual_library_card/_version.py + echo "__commit__ = '$(dunamai from git --format {commit} --full-commit)'" >> virtual_library_card/_version.py + echo "__branch__ = '$(dunamai from git --format {branch})'" >> virtual_library_card/_version.py + + # See comment here: https://github.com/actions/runner-images/issues/1187#issuecomment-686735760 + - name: Disable network offload + run: sudo ethtool -K eth0 tx off rx off + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Generate tags + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository_owner }}/virtual-library-card + tags: | + type=raw,value=latest,enable=${{ github.ref_name == 'main' }},priority=10 + type=semver,pattern={{major}}.{{minor}},priority=10 + type=semver,pattern={{version}},priority=20 + type=ref,event=branch,priority=30 + type=sha,priority=40 + + # We use docker/metadata-action to generate tags, instead of using string + # interpolation, because it properly handles making sure special + # characters are escaped, and the repo owner string is lowercase. + - name: Generate tags for cache image + id: cache-meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository_owner }}/virtual-library-card + tags: | + type=raw,value=latest + if: github.ref_type == 'branch' && github.ref_name != 'main' + + - name: Build image (with cache) + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64, linux/arm64 + cache-from: type=registry,ref=${{ fromJSON(steps.cache-meta.outputs.json).tags[0] }} + if: github.ref_type == 'branch' && github.ref_name != 'main' + + - name: Build image (full) + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64, linux/arm64 + cache-to: type=inline + if: github.ref_type == 'tag' || github.ref_name == 'main'