Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/dev-0-ci-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Dev CI/CD
on:
push:
branches:
- dev
jobs:
build:
if: github.ref == 'refs/heads/dev'
uses: ./.github/workflows/dev-1-ci.yaml
with:
environment: dev
image_repository: ${{ vars.DOCKER_IMAGE }}
push_image: ${{ github.event_name == 'push' }}
secrets:
docker_hub_username: ${{ secrets.DOCKER_HUB_USERNAME }}
docker_hub_access_token: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

deploy:
if: github.ref == 'refs/heads/dev'
uses: ./.github/workflows/dev-2-cd.yaml
needs: build
with:
environment: dev
image_repository: ${{ vars.DOCKER_IMAGE }}
image_tag: ${{ needs.build.outputs.image_tag }}
deployment_repository: ${{ vars.ARGOCD_REPOSITORY }}
deployment_ref: ${{ vars.ARGOCD_REF || 'main' }}
image_repository_path: ${{ vars.ARGOCD_IMAGE_REPOSITORY_PATH || 'control-front.image.repository' }}
image_tag_path: ${{ vars.ARGOCD_IMAGE_TAG_PATH || 'control-front.image.tag' }}
argocd_values_file: ${{ vars.ARGOCD_VALUES_FILE }}
secrets:
token: ${{ secrets.ARGOCD_GH_TOKEN }}
74 changes: 74 additions & 0 deletions .github/workflows/dev-1-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Dev CI - Build and Push Image

on:
workflow_call:
inputs:
environment:
description: GitHub Environment used for this build
required: true
type: string
image_repository:
description: Docker Hub image repository for the dev environment
required: true
type: string
push_image:
description: Whether to push the image to Docker Hub
required: false
default: false
type: boolean
secrets:
docker_hub_username:
required: false
docker_hub_access_token:
required: false
outputs:
image_tag:
description: Tag of the built dev image
value: ${{ jobs.build.outputs.image_tag }}

jobs:
build:
name: Build dev image
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
outputs:
image_tag: ${{ steps.image.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate image repository
env:
IMAGE_REPOSITORY: ${{ inputs.image_repository }}
run: test -n "$IMAGE_REPOSITORY"

- name: Set image tag
id: image
run: echo "tag=dev-${GITHUB_SHA}" >> "$GITHUB_OUTPUT"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
if: inputs.push_image
uses: docker/login-action@v4
with:
username: ${{ secrets.docker_hub_username }}
password: ${{ secrets.docker_hub_access_token }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ inputs.push_image }}
tags: |
${{ inputs.image_repository }}:${{ steps.image.outputs.tag }}
${{ inputs.image_repository }}:dev-latest
build-args: |
NEXT_PUBLIC_API_URL=${{ vars.NEXT_PUBLIC_API_URL }}
cache-from: type=gha,scope=dev
cache-to: type=gha,mode=max,scope=dev
75 changes: 75 additions & 0 deletions .github/workflows/dev-2-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Dev CD - Update Image on Deployment Repository

on:
workflow_call:
inputs:
environment:
description: GitHub Environment used for this deployment
required: true
type: string
image_repository:
required: true
type: string
image_tag:
required: true
type: string
deployment_repository:
required: true
type: string
deployment_ref:
required: false
default: main
type: string
image_repository_path:
required: false
default: .image.repository
type: string
image_tag_path:
required: false
default: .image.tag
type: string
argocd_values_file:
required: true
type: string
secrets:
token:
required: true

jobs:
update-image:
name: Update dev image in GitOps repository
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout deployment repository
uses: actions/checkout@v4
with:
repository: ${{ inputs.deployment_repository }}
ref: ${{ inputs.deployment_ref }}
token: ${{ secrets.token }}
path: deployment-config

- name: Set up yq
uses: shiipou/setup-yq-action@v2.2.0

- name: Update image repository and tag
env:
VALUES_FILE: ${{ vars.ARGOCD_VALUES_FILE }}
IMAGE_REPOSITORY: ${{ inputs.image_repository }}
IMAGE_TAG: ${{ inputs.image_tag }}
IMAGE_REPOSITORY_PATH: ${{ inputs.image_repository_path }}
IMAGE_TAG_PATH: ${{ inputs.image_tag_path }}
run: |
test -n "$VALUES_FILE"
test -f "deployment-config/$VALUES_FILE"
yq -i 'eval(strenv(IMAGE_REPOSITORY_PATH)) = strenv(IMAGE_REPOSITORY) | eval(strenv(IMAGE_TAG_PATH)) = strenv(IMAGE_TAG)' "deployment-config/$VALUES_FILE"
git -C deployment-config config user.email "github-actions[bot]@users.noreply.github.com"
git -C deployment-config config user.name "github-actions[bot]"
git -C deployment-config add "$VALUES_FILE"
if git -C deployment-config diff --cached --quiet; then
echo "Image values are already up to date."
else
git -C deployment-config commit -m "Deploy dev image $IMAGE_TAG"
git -C deployment-config push
fi
37 changes: 0 additions & 37 deletions .github/workflows/docker-image.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/prod-0-ci-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Prod CI/CD

on:
push:
branches:
- main

jobs:
build:
if: github.ref == 'refs/heads/main'
uses: ./.github/workflows/prod-1-ci.yaml
with:
environment: prod
image_repository: ${{ vars.DOCKER_IMAGE }}
push_image: ${{ github.event_name == 'push' }}
secrets:
docker_hub_username: ${{ secrets.DOCKER_HUB_USERNAME }}
docker_hub_access_token: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

deploy:
if: github.ref == 'refs/heads/main'
uses: ./.github/workflows/prod-2-cd.yaml
needs: build
with:
environment: prod
image_repository: ${{ vars.DOCKER_IMAGE }}
image_tag: ${{ needs.build.outputs.image_tag }}
deployment_repository: ${{ vars.ARGOCD_REPOSITORY }}
deployment_ref: ${{ vars.ARGOCD_REF || 'main' }}
image_repository_path: ${{ vars.ARGOCD_IMAGE_REPOSITORY_PATH || 'control-front.image.repository' }}
image_tag_path: ${{ vars.ARGOCD_IMAGE_TAG_PATH || 'control-front.image.tag' }}
argocd_values_file: ${{ vars.ARGOCD_VALUES_FILE }}
secrets:
token: ${{ secrets.ARGOCD_GH_TOKEN }}
74 changes: 74 additions & 0 deletions .github/workflows/prod-1-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Prod CI - Build and Push Image

on:
workflow_call:
inputs:
environment:
description: GitHub Environment used for this build
required: true
type: string
image_repository:
description: Docker Hub image repository
required: true
type: string
push_image:
description: Whether to push the image to Docker Hub
required: false
default: false
type: boolean
secrets:
docker_hub_username:
required: false
docker_hub_access_token:
required: false
outputs:
image_tag:
description: Tag of the built production image
value: ${{ jobs.build.outputs.image_tag }}

jobs:
build:
name: Build production image
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
outputs:
image_tag: ${{ steps.image.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate image repository
env:
IMAGE_REPOSITORY: ${{ inputs.image_repository }}
run: test -n "$IMAGE_REPOSITORY"

- name: Set image tag
id: image
run: echo "tag=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
if: inputs.push_image
uses: docker/login-action@v4
with:
username: ${{ secrets.docker_hub_username }}
password: ${{ secrets.docker_hub_access_token }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ inputs.push_image }}
tags: |
${{ inputs.image_repository }}:${{ steps.image.outputs.tag }}
${{ inputs.image_repository }}:latest
build-args: |
NEXT_PUBLIC_API_URL=${{ vars.NEXT_PUBLIC_API_URL }}
cache-from: type=gha,scope=prod
cache-to: type=gha,mode=max,scope=prod
Loading