Skip to content

Commit

Permalink
ENG-1501 - Add support for image variants/monorepos (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
daanpersoons authored Nov 23, 2024
1 parent f8e8be9 commit acb2a3a
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 12 deletions.
45 changes: 42 additions & 3 deletions .github/workflows/workflow-build-and-deploy-digitalocean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ on:
description: Image name (fallback to repository name)
type: string
required: false
image-variants:
description: List of variants to build (folders in monorepo), separated by commas
type: string
required: false
secrets:
DIGITALOCEAN_API_USER:
description: DigitalOcean user email
Expand All @@ -32,30 +36,65 @@ on:
required: true

jobs:
generate-matrix:
name: Generate job matrices
runs-on: ubuntu-latest
outputs:
variants: ${{ steps.monorepo.outputs.matrix || steps.normalrepo.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: .github
- name: Monorepo Matrix check
id: monorepo
if: hashFiles('.github/monorepo-rollout-filters.yaml') != ''
uses: wisemen-digital/devops-ga-changed-paths-filter@main
with:
filter-file: .github/monorepo-rollout-filters.yaml
changes-override: ${{ inputs.image-variants }}
- name: Normal Repo Fallback
id: normalrepo
if: hashFiles('.github/monorepo-rollout-filters.yaml') == ''
run: echo 'matrix=[{"environment":"","path":""}]' >> $GITHUB_OUTPUT;

build-and-deploy:
name: Build & Deploy to ${{ inputs.environment }}
name: Build & Deploy ${{ matrix.variant.path }} to ${{ inputs.environment }}
needs: [generate-matrix]
if: ${{ needs.generate-matrix.outputs.variants != '[]' }}
strategy:
matrix:
variant: ${{ fromJson(needs.generate-matrix.outputs.variants) }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Prepare environment
run: |
echo "image=`basename ${{ inputs.image || github.repository }}`" >> "$GITHUB_ENV"
if [ -z "${{ matrix.variant.path }}" ]; then
echo "image_suffix=" >> "$GITHUB_ENV"
echo "rollout_labels=${{ vars.K8S_LABELS }}" >> "$GITHUB_ENV"
else
echo "image_suffix=-${{ matrix.variant.path }}" >> "$GITHUB_ENV"
echo "rollout_labels=${{ vars.K8S_LABELS }},variant=${{ matrix.variant.path }}" >> "$GITHUB_ENV"
fi
- name: Docker build & push
uses: wisemen-digital/devops-ga-docker-build-push@main
with:
container-registry: ${{ vars.CONTAINER_REGISTRY_ENDPOINT }}
container-registry-username: ${{ secrets.DIGITALOCEAN_API_USER }}
container-registry-password: ${{ secrets.DIGITALOCEAN_API_TOKEN }}
github-access-token: ${{ secrets.GITHUB_TOKEN }}
image: ${{ env.image }}
image: ${{ env.image }}${{ env.image_suffix }}
tag: ${{ inputs.environment }}
platforms: ${{ vars.CONTAINER_PLATFORMS }}
target: ${{ matrix.variant.path }}
- name: Rollout on cluster
uses: wisemen-digital/devops-ga-k8s-rollout@main
with:
vendor: digitalocean
cluster-id: ${{ vars.K8S_CLUSTER_ID }}
rollout-deployments: ${{ vars.K8S_DEPLOYMENTS }}
rollout-labels: ${{ vars.K8S_LABELS }}
rollout-labels: ${{ env.rollout_labels }}
rollout-namespace: ${{ vars.K8S_NAMESPACE }}
digitalocean-api-token: ${{ secrets.DIGITALOCEAN_API_TOKEN }}
45 changes: 42 additions & 3 deletions .github/workflows/workflow-build-and-deploy-scaleway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ on:
description: Image name (fallback to repository name)
type: string
required: false
image-variants:
description: List of variants to build (folders in monorepo), separated by commas
type: string
required: false
# Legacy parameters
cluster-deployments:
description: UNUSED
Expand Down Expand Up @@ -60,31 +64,66 @@ on:
required: true

jobs:
generate-matrix:
name: Generate job matrices
runs-on: ubuntu-latest
outputs:
variants: ${{ steps.monorepo.outputs.matrix || steps.normalrepo.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: .github
- name: Monorepo Matrix check
id: monorepo
if: hashFiles('.github/monorepo-rollout-filters.yaml') != ''
uses: wisemen-digital/devops-ga-changed-paths-filter@main
with:
filter-file: .github/monorepo-rollout-filters.yaml
changes-override: ${{ inputs.image-variants }}
- name: Normal Repo Fallback
id: normalrepo
if: hashFiles('.github/monorepo-rollout-filters.yaml') == ''
run: echo 'matrix=[{"environment":"","path":""}]' >> $GITHUB_OUTPUT;

build-and-deploy:
name: Build & Deploy to ${{ inputs.environment }}
name: Build & Deploy ${{ matrix.variant.path }} to ${{ inputs.environment }}
needs: [generate-matrix]
if: ${{ needs.generate-matrix.outputs.variants != '[]' }}
strategy:
matrix:
variant: ${{ fromJson(needs.generate-matrix.outputs.variants) }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Prepare environment
run: |
echo "image=`basename ${{ inputs.image || github.repository }}`" >> "$GITHUB_ENV"
if [ -z "${{ matrix.variant.path }}" ]; then
echo "image_suffix=" >> "$GITHUB_ENV"
echo "rollout_labels=${{ vars.K8S_LABELS }}" >> "$GITHUB_ENV"
else
echo "image_suffix=-${{ matrix.variant.path }}" >> "$GITHUB_ENV"
echo "rollout_labels=${{ vars.K8S_LABELS }},variant=${{ matrix.variant.path }}" >> "$GITHUB_ENV"
fi
- name: Docker build & push
uses: wisemen-digital/devops-ga-docker-build-push@main
with:
container-registry: ${{ vars.CONTAINER_REGISTRY_ENDPOINT }}
container-registry-username: nologin
container-registry-password: ${{ secrets.SCALEWAY_SECRET_KEY }}
github-access-token: ${{ secrets.GITHUB_TOKEN }}
image: ${{ env.image }}
image: ${{ env.image }}${{ env.image_suffix }}
tag: ${{ inputs.environment }}
platforms: ${{ vars.CONTAINER_PLATFORMS }}
target: ${{ matrix.variant.path }}
- name: Rollout on cluster
uses: wisemen-digital/devops-ga-k8s-rollout@main
with:
vendor: scaleway
cluster-id: ${{ vars.K8S_CLUSTER_ID }}
rollout-deployments: ${{ vars.K8S_DEPLOYMENTS }}
rollout-labels: ${{ vars.K8S_LABELS }}
rollout-labels: ${{ env.rollout_labels }}
rollout-namespace: ${{ vars.K8S_NAMESPACE }}
scaleway-organization-id: ${{ vars.SCALEWAY_ORGANIZATION_ID }}
scaleway-project-id: ${{ vars.SCALEWAY_PROJECT_ID }}
Expand Down
44 changes: 41 additions & 3 deletions .github/workflows/workflow-promote-to-environment-digitalocean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ on:
description: Image name (fallback to repository name)
type: string
required: false
image-variants:
description: List of variants to roll out (folders in monorepo), separated by commas
type: string
required: false
secrets:
DIGITALOCEAN_API_USER:
description: DigitalOcean user email
Expand All @@ -39,21 +43,55 @@ on:
required: true

jobs:
generate-matrix:
name: Generate job matrices
runs-on: ubuntu-latest
outputs:
variants: ${{ steps.monorepo.outputs.matrix || steps.normalrepo.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: .github
- name: Monorepo Matrix check
id: monorepo
if: hashFiles('.github/monorepo-rollout-filters.yaml') != ''
uses: wisemen-digital/devops-ga-changed-paths-filter@main
with:
filter-file: .github/monorepo-rollout-filters.yaml
changes-override: ${{ inputs.image-variants }}
- name: Normal Repo Fallback
id: normalrepo
if: hashFiles('.github/monorepo-rollout-filters.yaml') == ''
run: echo 'matrix=[{"environment":"","path":""}]' >> $GITHUB_OUTPUT;

promote-tag:
name: Promote to ${{ inputs.environment-target }}
name: Promote ${{ matrix.variant.path }} to ${{ inputs.environment-target }}
needs: [generate-matrix]
if: ${{ needs.generate-matrix.outputs.variants != '[]' }}
strategy:
matrix:
variant: ${{ fromJson(needs.generate-matrix.outputs.variants) }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment-target }}
steps:
- name: Prepare environment
run: |
echo "image=`basename ${{ inputs.image || github.repository }}`" >> "$GITHUB_ENV"
if [ -z "${{ matrix.variant.path }}" ]; then
echo "image_suffix=" >> "$GITHUB_ENV"
echo "rollout_labels=${{ vars.K8S_LABELS }}" >> "$GITHUB_ENV"
else
echo "image_suffix=-${{ matrix.variant.path }}" >> "$GITHUB_ENV"
echo "rollout_labels=${{ vars.K8S_LABELS }},variant=${{ matrix.variant.path }}" >> "$GITHUB_ENV"
fi
- name: Re-tag image
uses: wisemen-digital/devops-ga-docker-promote-tag@main
with:
container-registry: ${{ vars.CONTAINER_REGISTRY_ENDPOINT }}
container-registry-username: ${{ secrets.DIGITALOCEAN_API_USER }}
container-registry-password: ${{ secrets.DIGITALOCEAN_API_TOKEN }}
image: ${{ env.image }}
image: ${{ env.image }}${{ env.image_suffix }}
source-tag: ${{ inputs.environment-source }}
target-tag: ${{ inputs.environment-target }}
tag-map: ${{ inputs.environment-map }}
Expand All @@ -63,6 +101,6 @@ jobs:
vendor: digitalocean
cluster-id: ${{ vars.K8S_CLUSTER_ID }}
rollout-deployments: ${{ vars.K8S_DEPLOYMENTS }}
rollout-labels: ${{ vars.K8S_LABELS }}
rollout-labels: ${{ env.rollout_labels }}
rollout-namespace: ${{ vars.K8S_NAMESPACE }}
digitalocean-api-token: ${{ secrets.DIGITALOCEAN_API_TOKEN }}
44 changes: 41 additions & 3 deletions .github/workflows/workflow-promote-to-environment-scaleway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ on:
description: Image name (fallback to repository name)
type: string
required: false
image-variants:
description: List of variants to roll out (folders in monorepo), separated by commas
type: string
required: false
# Legacy parameters
cluster-deployments:
description: UNUSED
Expand Down Expand Up @@ -67,21 +71,55 @@ on:
required: true

jobs:
generate-matrix:
name: Generate job matrices
runs-on: ubuntu-latest
outputs:
variants: ${{ steps.monorepo.outputs.matrix || steps.normalrepo.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: .github
- name: Monorepo Matrix check
id: monorepo
if: hashFiles('.github/monorepo-rollout-filters.yaml') != ''
uses: wisemen-digital/devops-ga-changed-paths-filter@main
with:
filter-file: .github/monorepo-rollout-filters.yaml
changes-override: ${{ inputs.image-variants }}
- name: Normal Repo Fallback
id: normalrepo
if: hashFiles('.github/monorepo-rollout-filters.yaml') == ''
run: echo 'matrix=[{"environment":"","path":""}]' >> $GITHUB_OUTPUT;

promote-tag:
name: Promote to ${{ inputs.environment-target }}
name: Promote ${{ matrix.variant.path }} to ${{ inputs.environment-target }}
needs: [generate-matrix]
if: ${{ needs.generate-matrix.outputs.variants != '[]' }}
strategy:
matrix:
variant: ${{ fromJson(needs.generate-matrix.outputs.variants) }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment-target }}
steps:
- name: Prepare environment
run: |
echo "image=`basename ${{ inputs.image || github.repository }}`" >> "$GITHUB_ENV"
if [ -z "${{ matrix.variant.path }}" ]; then
echo "image_suffix=" >> "$GITHUB_ENV"
echo "rollout_labels=${{ vars.K8S_LABELS }}" >> "$GITHUB_ENV"
else
echo "image_suffix=-${{ matrix.variant.path }}" >> "$GITHUB_ENV"
echo "rollout_labels=${{ vars.K8S_LABELS }},variant=${{ matrix.variant.path }}" >> "$GITHUB_ENV"
fi
- name: Re-tag image
uses: wisemen-digital/devops-ga-docker-promote-tag@main
with:
container-registry: ${{ vars.CONTAINER_REGISTRY_ENDPOINT }}
container-registry-username: nologin
container-registry-password: ${{ secrets.SCALEWAY_SECRET_KEY }}
image: ${{ env.image }}
image: ${{ env.image }}${{ env.image_suffix }}
source-tag: ${{ inputs.environment-source }}
target-tag: ${{ inputs.environment-target }}
tag-map: ${{ inputs.environment-map }}
Expand All @@ -91,7 +129,7 @@ jobs:
vendor: scaleway
cluster-id: ${{ vars.K8S_CLUSTER_ID }}
rollout-deployments: ${{ vars.K8S_DEPLOYMENTS }}
rollout-labels: ${{ vars.K8S_LABELS }}
rollout-labels: ${{ env.rollout_labels }}
rollout-namespace: ${{ vars.K8S_NAMESPACE }}
scaleway-organization-id: ${{ vars.SCALEWAY_ORGANIZATION_ID }}
scaleway-project-id: ${{ vars.SCALEWAY_PROJECT_ID }}
Expand Down
1 change: 1 addition & 0 deletions Docs/workflow-build-and-deploy-digitalocean.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Note: this workflow is meant for deployments to **DigitalOcean**.
| ----- | ----------- |
| `environment` | Target environment to deploy to, usually `development` |
| `image` | Image name (fallback to repository name) |
| `image-variants` | List of variants to build (folders in monorepo), separated by commas |

| Secret | Description |
| ------ | ----------- |
Expand Down
1 change: 1 addition & 0 deletions Docs/workflow-build-and-deploy-scaleway.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Note: this workflow is meant for deployments to **Scaleway**.
| ----- | ----------- |
| `environment` | Target environment to deploy to, usually `development` |
| `image` | Image name (fallback to repository name) |
| `image-variants` | List of variants to build (folders in monorepo), separated by commas |

| Secret | Description |
| ------ | ----------- |
Expand Down
1 change: 1 addition & 0 deletions Docs/workflow-promote-to-environment-digitalocean.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Note: this workflow is meant for deployments to **DigitalOcean**.
| `environment-target` | Target environment to deploy to |
| `environment-map` | Custom environment mapping (JSON object) |
| `image` | Image name (fallback to repository name) |
| `image-variants` | List of variants to roll out (folders in monorepo), separated by commas |

| Secret | Description |
| ------ | ----------- |
Expand Down
1 change: 1 addition & 0 deletions Docs/workflow-promote-to-environment-scaleway.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Note: this workflow is meant for deployments to **Scaleway**.
| `environment-target` | Target environment to deploy to |
| `environment-map` | Custom environment mapping (JSON object) |
| `image` | Image name (fallback to repository name) |
| `image-variants` | List of variants to roll out (folders in monorepo), separated by commas |

| Secret | Description |
| ------ | ----------- |
Expand Down

0 comments on commit acb2a3a

Please sign in to comment.