Skip to content

Commit

Permalink
Merge pull request #21 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 022d74d + 19ebb29 commit 4aa248f
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 98 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-4-1-4-ubuntu-16-04:
build-4-1-4:
runs-on: ubuntu-latest
env:
VARIANT: 4.1.4-ubuntu-16.04
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-4.1.4-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.VARIANT }}-
${{ runner.os }}-buildx-4.1.4-
${{ 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-4-1-4-ubuntu-16-04
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="4.1.4-ubuntu-16.04"
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: 4.1.4-ubuntu-16.04 - 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/v7,linux/arm64,linux/s390x
push: false
tags: |
${{ github.repository }}:${{ env.REF_VARIANT }}
${{ github.repository }}:${{ env.REF_SHA_VARIANT }}
${{ github.repository }}:${{ steps.prep-4-1-4-ubuntu-16-04.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-4-1-4-ubuntu-16-04.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: 4.1.4-ubuntu-16.04 - 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/v7,linux/arm64,linux/s390x
push: true
tags: |
${{ github.repository }}:${{ env.REF_VARIANT }}
${{ github.repository }}:${{ env.REF_SHA_VARIANT }}
${{ github.repository }}:${{ steps.prep-4-1-4-ubuntu-16-04.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-4-1-4-ubuntu-16-04.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: 4.1.4-ubuntu-16.04 - Build and push (release)
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
context: variants/4.1.4-ubuntu-16.04
platforms: linux/386,linux/amd64,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-4-1-4-ubuntu-16-04.outputs.VARIANT }}
${{ github.repository }}:${{ steps.prep-4-1-4-ubuntu-16-04.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-4-1-4-ubuntu-16-04.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-4-1-4-ubuntu-16-04]
needs:
- build-4-1-4
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-4-1-4-ubuntu-16-04]
needs:
- build-4-1-4
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-4-1-4-ubuntu-16-04]
needs:
- build-4-1-4
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
26 changes: 16 additions & 10 deletions generate/definitions/VARIANTS.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
$local:VERSIONS = @(
'4.1.4'
)
# Docker image variants' definitions
$VARIANTS = @(
@{
_metadata = @{
components = @( 'varnishdashboard' )
platforms = 'linux/386,linux/amd64,linux/arm/v7,linux/arm64,linux/s390x'
VARNISH_AGENT_VERSION = '4.1.4'
VARNISH_DASHBOARD_COMMIT = "e2cc1c854941c9fac18bdfedba2819fa766a5549"
# distro = 'ubuntu'
# distro_version = '16.04'
foreach ($v in $local:VERSIONS) {
@{
_metadata = @{
components = @( 'varnishdashboard' )
platforms = 'linux/386,linux/amd64,linux/arm/v7,linux/arm64,linux/s390x'
VARNISH_AGENT_VERSION = $v
VARNISH_DASHBOARD_COMMIT = "e2cc1c854941c9fac18bdfedba2819fa766a5549"
# distro = 'ubuntu'
# distro_version = '16.04'
job_group_key = $v
}
tag = "$v-ubuntu-16.04"
tag_as_latest = $true
}
tag = '4.1.4-ubuntu-16.04'
tag_as_latest = $true
}
)

Expand Down
Loading

0 comments on commit 4aa248f

Please sign in to comment.