Add docker build to CI pipeline
This commit is contained in:
parent
57427eab87
commit
5c754e22b4
1 changed files with 47 additions and 3 deletions
50
.github/workflows/flaskr-ci.yaml
vendored
50
.github/workflows/flaskr-ci.yaml
vendored
|
|
@ -3,10 +3,8 @@ name: Build Flaskr App
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
tests:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Set up Python 3.11
|
- name: Set up Python 3.11
|
||||||
|
|
@ -32,3 +30,49 @@ jobs:
|
||||||
pwd
|
pwd
|
||||||
cd examples/tutorial
|
cd examples/tutorial
|
||||||
pytest
|
pytest
|
||||||
|
# Build Docker image in a separate job so that it's not taited by cached python build/test files
|
||||||
|
build-image:
|
||||||
|
needs: tests
|
||||||
|
permissions:
|
||||||
|
# Required permission to push images with the built-in GITHUB_TOKEN
|
||||||
|
packages: write
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Set job vars
|
||||||
|
id: vars
|
||||||
|
run: echo "sha_short=${GITHUB_SHA:0:10}" >> $GITHUB_OUTPUT
|
||||||
|
# This is a separate action that sets up buildx runner
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
# So now you can use Actions' own caching!
|
||||||
|
- name: Cache Docker layers
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: /tmp/.buildx-cache
|
||||||
|
key: flaskr-buildx-${{ github.ref_name }}
|
||||||
|
restore-keys: |
|
||||||
|
flaskr-buildx-main
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Build Docker image and push to GHCR
|
||||||
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: examples/tutorial
|
||||||
|
push: true
|
||||||
|
tags: "ghcr.io/${{ github.repository }}:${{ steps.vars.outputs.sha_short }}"
|
||||||
|
cache-from: type=local,src=/tmp/.buildx-cache
|
||||||
|
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
||||||
|
# This ugly bit is necessary if you don't want your cache to grow forever
|
||||||
|
# until it hits GitHub's limit of 5GB.
|
||||||
|
# Temp fix
|
||||||
|
# https://github.com/docker/build-push-action/issues/252
|
||||||
|
# https://github.com/moby/buildkit/issues/1896
|
||||||
|
- name: Move cache
|
||||||
|
run: |
|
||||||
|
rm -rf /tmp/.buildx-cache
|
||||||
|
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue