Skip to content

Commit

Permalink
Merge pull request #12 from theohbrothers/enhancement/ci-add-support-…
Browse files Browse the repository at this point in the history
…for-incremental-variants

Enhancement (ci): Add support for incremental variants
  • Loading branch information
leojonathanoh authored Sep 25, 2023
2 parents 6324f61 + c4c77ab commit 0e0993a
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 97 deletions.
67 changes: 35 additions & 32 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ on:
pull_request:
branches:
- master
merge_group:
jobs:
test-nogitdiff:
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/powershell:7.2.2-alpine-3.14-20220318
image: mcr.microsoft.com/powershell:lts-7.2-alpine-3.17
steps:
- run: |
apk add --no-cache git
Expand All @@ -32,10 +33,8 @@ jobs:
run: |
git diff --exit-code
build-3-12:
build-0-0-0:
runs-on: ubuntu-latest
env:
VARIANT: 3.12
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -65,14 +64,22 @@ jobs:
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.VARIANT }}-${{ github.sha }}
key: ${{ runner.os }}-buildx-0.0.0-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.VARIANT }}-
${{ runner.os }}-buildx-0.0.0-
${{ runner.os }}-buildx-
- name: Login to Docker Hub registry
# Run on master and tags
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
password: ${{ secrets.DOCKERHUB_REGISTRY_PASSWORD }}

# This step generates the docker tags
- name: Prepare
id: prep
id: prep-3-12
run: |
set -e
Expand All @@ -85,24 +92,17 @@ jobs:
# Generate docker image tags
# E.g. 'v0.0.0-<variant>' and 'v0.0.0-abc0123-<variant>'
# E.g. 'master-<variant>' and 'master-abc0123-<variant>'
VARIANT="3.12"
REF_VARIANT="${REF}-${VARIANT}"
REF_SHA_VARIANT="${REF}-${SHA}-${VARIANT}"
# Pass variables to next step
echo "VARIANT_BUILD_DIR=$VARIANT_BUILD_DIR" >> $GITHUB_ENV
echo "VARIANT=$VARIANT" >> $GITHUB_ENV
echo "REF_VARIANT=$REF_VARIANT" >> $GITHUB_ENV
echo "REF_SHA_VARIANT=$REF_SHA_VARIANT" >> $GITHUB_ENV
- name: Login to Docker Hub registry
# Run on master and tags
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
password: ${{ secrets.DOCKERHUB_REGISTRY_PASSWORD }}
echo "VARIANT_BUILD_DIR=$VARIANT_BUILD_DIR" >> $GITHUB_OUTPUT
echo "VARIANT=$VARIANT" >> $GITHUB_OUTPUT
echo "REF_VARIANT=$REF_VARIANT" >> $GITHUB_OUTPUT
echo "REF_SHA_VARIANT=$REF_SHA_VARIANT" >> $GITHUB_OUTPUT
- name: Build (PRs)
- name: 3.12 - Build (PRs)
# Run only on pull requests
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v3
Expand All @@ -111,12 +111,12 @@ jobs:
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x
push: false
tags: |
${{ github.repository }}:${{ env.REF_VARIANT }}
${{ github.repository }}:${{ env.REF_SHA_VARIANT }}
${{ github.repository }}:${{ steps.prep-3-12.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-3-12.outputs.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Build and push (master)
- name: 3.12 - Build and push (master)
# Run only on master
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v3
Expand All @@ -125,22 +125,22 @@ jobs:
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x
push: true
tags: |
${{ github.repository }}:${{ env.REF_VARIANT }}
${{ github.repository }}:${{ env.REF_SHA_VARIANT }}
${{ github.repository }}:${{ steps.prep-3-12.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-3-12.outputs.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Build and push (release)
- name: 3.12 - Build and push (release)
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
context: variants/3.12
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x
push: true
tags: |
${{ github.repository }}:${{ env.VARIANT }}
${{ github.repository }}:${{ env.REF_VARIANT }}
${{ github.repository }}:${{ env.REF_SHA_VARIANT }}
${{ github.repository }}:${{ steps.prep-3-12.outputs.VARIANT }}
${{ github.repository }}:${{ steps.prep-3-12.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-3-12.outputs.REF_SHA_VARIANT }}
${{ github.repository }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
Expand All @@ -154,7 +154,8 @@ jobs:
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
update-draft-release:
needs: [build-3-12]
needs:
- build-0-0-0
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
Expand All @@ -167,7 +168,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-draft-release:
needs: [build-3-12]
needs:
- build-0-0-0
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
Expand All @@ -182,7 +184,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

update-dockerhub-description:
needs: [build-3-12]
needs:
- build-0-0-0
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 1 addition & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"-c",
"Generate-DockerImageVariants ."
],
"group": {
"kind": "build",
"isDefault": true
}
"group": "build"
},
{
"label": "Install DockerImageVariants module",
Expand Down
24 changes: 15 additions & 9 deletions generate/definitions/VARIANTS.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
$local:VERSIONS = @(
'0.0.0'
)
$VARIANTS = @(
@{
# Metadata object
_metadata = @{
distro = 'alpine'
distro_version = '3.12'
platforms = 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x'
foreach ($v in $local:VERSIONS) {
@{
# Metadata object
_metadata = @{
distro = 'alpine'
distro_version = '3.12'
platforms = 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x'
job_group_key = $v
}
# Docker image tag. E.g. '3.12'
tag = '3.12'
tag_as_latest = $true
}
# Docker image tag. E.g. '3.12'
tag = '3.12'
tag_as_latest = $true
}
)

Expand Down
Loading

0 comments on commit 0e0993a

Please sign in to comment.