Parallel jobs (#1)
Implemented parallel docker builds on Github Actions
This commit is contained in:
parent
4bc965f6ef
commit
24530f4ebd
1 changed files with 151 additions and 17 deletions
168
.github/workflows/package.yaml
vendored
168
.github/workflows/package.yaml
vendored
|
|
@ -19,14 +19,13 @@ env:
|
||||||
jobs:
|
jobs:
|
||||||
# Push image to GitHub Packages.
|
# Push image to GitHub Packages.
|
||||||
# See also https://docs.docker.com/docker-hub/builds/
|
# See also https://docs.docker.com/docker-hub/builds/
|
||||||
push:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [ "3.10" ]
|
python-version: [ "3.10" ]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
packages: write
|
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
@ -43,6 +42,122 @@ jobs:
|
||||||
python setup.py bdist_wheel
|
python setup.py bdist_wheel
|
||||||
cp dist/*.whl docker/root
|
cp dist/*.whl docker/root
|
||||||
|
|
||||||
|
- name: Save Python build cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: docker/root
|
||||||
|
key: ${{github.sha}}
|
||||||
|
|
||||||
|
|
||||||
|
# Build ARM64 container
|
||||||
|
package-arm64:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [
|
||||||
|
build
|
||||||
|
]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Restore Python build cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: docker/root
|
||||||
|
key: ${{github.sha}}
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
with:
|
||||||
|
platforms: linux/arm64
|
||||||
|
|
||||||
|
- name: Docker Setup Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2.0.0
|
||||||
|
|
||||||
|
- name: Build Docker Image
|
||||||
|
run: |
|
||||||
|
docker buildx build \
|
||||||
|
--platform=linux/arm64 \
|
||||||
|
--cache-to=type=local,dest=/tmp/build-cache/arm64 \
|
||||||
|
--tag $IMAGE_NAME \
|
||||||
|
--label "runnumber=${GITHUB_RUN_ID}" \
|
||||||
|
docker/
|
||||||
|
|
||||||
|
- name: Save ARM64 build cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: /tmp/build-cache/arm64
|
||||||
|
key: ${{github.sha}}
|
||||||
|
|
||||||
|
|
||||||
|
# Build AMD64 container
|
||||||
|
package-amd64:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [
|
||||||
|
build
|
||||||
|
]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Restore Python build cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: docker/root
|
||||||
|
key: ${{github.sha}}
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
with:
|
||||||
|
platforms: linux/amd64
|
||||||
|
|
||||||
|
- name: Docker Setup Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2.0.0
|
||||||
|
|
||||||
|
- name: Build Docker Image
|
||||||
|
run: |
|
||||||
|
docker buildx build \
|
||||||
|
--platform=linux/amd64 \
|
||||||
|
--cache-to=type=local,dest=/tmp/build-cache/amd64 \
|
||||||
|
--tag $IMAGE_NAME \
|
||||||
|
--label "runnumber=${GITHUB_RUN_ID}" \
|
||||||
|
docker/
|
||||||
|
|
||||||
|
- name: Save AMD64 build cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: /tmp/build-cache/amd64
|
||||||
|
key: ${{github.sha}}
|
||||||
|
|
||||||
|
|
||||||
|
# On master branch, build the docker manifest file from the cached docker builds and push to the registry
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [
|
||||||
|
build,
|
||||||
|
package-arm64,
|
||||||
|
package-amd64
|
||||||
|
]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
packages: write
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
if: contains('refs/heads/master', github.ref) || ${{ github.ref }} =~ ^refs\/tags\/v.*
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Restore Python build cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: docker/root
|
||||||
|
key: ${{github.sha}}
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@v2
|
||||||
with:
|
with:
|
||||||
|
|
@ -51,9 +166,6 @@ jobs:
|
||||||
- name: Docker Setup Buildx
|
- name: Docker Setup Buildx
|
||||||
uses: docker/setup-buildx-action@v2.0.0
|
uses: docker/setup-buildx-action@v2.0.0
|
||||||
|
|
||||||
- name: Build Docker Image
|
|
||||||
run: docker buildx build --platform=linux/amd64,linux/arm64 --cache-to=type=local,dest=/tmp/build-cache --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" docker/
|
|
||||||
|
|
||||||
- name: login to GitHub Container Registry
|
- name: login to GitHub Container Registry
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v1
|
||||||
with:
|
with:
|
||||||
|
|
@ -61,26 +173,48 @@ jobs:
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build preparations
|
- name: Restore ARM64 build cache
|
||||||
if: ${{ github.ref }} =~ ^refs\/heads\/master|^refs\/tags\/v.*
|
uses: actions/cache@v3
|
||||||
id: preperations
|
with:
|
||||||
run: |
|
path: /tmp/build-cache/arm64
|
||||||
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
|
key: ${{github.sha}}
|
||||||
|
|
||||||
|
- name: Restore AMD64 build cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: /tmp/build-cache/amd64
|
||||||
|
key: ${{github.sha}}
|
||||||
|
|
||||||
|
- name: Format image_id
|
||||||
|
id: formatted-image_id
|
||||||
|
run: |
|
||||||
|
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${IMAGE_NAME}
|
||||||
|
|
||||||
# Change all uppercase to lowercase
|
# Change all uppercase to lowercase
|
||||||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
|
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
|
||||||
|
echo IMAGE_ID=${IMAGE_ID}
|
||||||
|
|
||||||
|
echo ::set-output name=IMAGE_ID::${IMAGE_ID}
|
||||||
|
|
||||||
|
- name: Get the version
|
||||||
|
id: formatted_version
|
||||||
|
run: |
|
||||||
# Strip git ref prefix from version
|
# Strip git ref prefix from version
|
||||||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
|
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
|
||||||
# Strip "v" prefix from tag name
|
# Strip "v" prefix from tag name
|
||||||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
|
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
|
||||||
# Use Docker `latest` tag convention
|
# Use Docker `latest` tag convention
|
||||||
[ "$VERSION" == "master" ] && VERSION=latest
|
[ "$VERSION" == "master" ] && VERSION=latest
|
||||||
echo IMAGE_ID=$IMAGE_ID
|
echo VERSION=${VERSION}
|
||||||
echo VERSION=$VERSION
|
|
||||||
echo "::set-output name=IMAGE_TAG::$(
|
echo ::set-output name=VERSION::${VERSION}
|
||||||
echo $IMAGE_ID:$VERSION
|
|
||||||
)"
|
|
||||||
|
|
||||||
- name: Build Docker Image and push to registry
|
- name: Build Docker Image and push to registry
|
||||||
if: ${{ github.ref }} =~ ^refs\/heads\/master|^refs\/tags\/v.*
|
run: |
|
||||||
run: docker buildx build --push --platform=linux/amd64,linux/arm64 --cache-from=type=local,src=/tmp/build-cache --tag ${{ steps.preperations.outputs.IMAGE_TAG }} --label "runnumber=${GITHUB_RUN_ID}" docker/
|
docker buildx build --push \
|
||||||
|
--platform=linux/amd64,linux/arm64 \
|
||||||
|
--cache-from=type=local,src=/tmp/build-cache/amd64 \
|
||||||
|
--cache-from=type=local,src=/tmp/build-cache/arm64 \
|
||||||
|
--tag ${{ steps.formatted-image_id.outputs.IMAGE_ID }}:${{ steps.formatted_version.outputs.VERSION }} \
|
||||||
|
--label "runnumber=${GITHUB_RUN_ID}" \
|
||||||
|
docker/
|
||||||
Loading…
Reference in a new issue