Skip to content

Commit

Permalink
MAN-227 - use local build files
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Dec 19, 2024
1 parent 89adb96 commit 8d538b8
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 1 deletion.
79 changes: 79 additions & 0 deletions .github/actions/build-test-and-deploy/build_docker/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build and push docker image to registry
description: 'action to build and push docker image'

inputs:
repository_name:
description: Repository name
required: true
docker_registry:
description: Docker registry
required: true
registry_org:
description: Docker registry organisation
required: true
additional_docker_tag:
description: Additional docker tag that can be used to specify stable tags
required: false
push:
description: Push docker image to registry flag
required: true
app_version:
description: App version
required: true
HMPPS_QUAYIO_USER:
description: Docker registry username
required: false
HMPPS_QUAYIO_TOKEN:
description: Docker registry token
required: false

runs:
using: "composite"
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Docker login if Docker registry is quay.io
if: ${{ inputs.docker_registry == 'quay.io' }}
uses: docker/login-action@v3
with:
registry: ${{ inputs.docker_registry }}
username: ${{ inputs.HMPPS_QUAYIO_USER }}
password: ${{ inputs.HMPPS_QUAYIO_TOKEN }}

- name: Docker login if Docker registry is ghcr.io
if: ${{ inputs.docker_registry == 'ghcr.io' }}
uses: docker/login-action@v3
with:
registry: ${{ inputs.docker_registry }}
username: ${{ github.actor }}
password: ${{ github.token }}

# - name: Configure AWS credentials
# if: ${{ inputs.docker_registry == 'ecr' }}
# uses: aws-actions/configure-aws-credentials@v2
# with:
# aws-access-key-id: ${{ secrets.AWS_MGMT_ECR_ID }}
# aws-secret-access-key: ${{ secrets.AWS_MGMT_ECR_KEY }}
# aws-region: eu-west-2

# - name: Login to Amazon ECR
# if: ${{ inputs.docker_registry == 'ecr' }}
# uses: aws-actions/amazon-ecr-login@v1

- name: Build Docker images
uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
push: ${{ inputs.push }}
provenance: false
build-args: |
"BUILD_NUMBER=${{ inputs.app_version }}"
"GIT_REF=${{ github.sha }}"
"GIT_BRANCH=${{ github.ref_name }}"
tags: |
${{ inputs.docker_registry}}/${{ inputs.registry_org }}/${{ github.event.repository.name }}:latest
${{ inputs.docker_registry}}/${{ inputs.registry_org }}/${{ github.event.repository.name }}:${{ inputs.app_version }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Build and push multi-platform docker image to registry
description: action to build and push a multi-platform docker image

inputs:
repository_name:
description: Repository name
required: true
docker_registry:
description: Docker registry
required: true
registry_org:
description: Docker registry organisation
required: true
additional_docker_tag:
description: Additional docker tag that can be used to specify stable tags
required: false
push:
description: Push docker image to registry flag
required: true
app_version:
description: App version
required: true
HMPPS_QUAYIO_USER:
description: Docker registry username
required: false
HMPPS_QUAYIO_TOKEN:
description: Docker registry token
required: false


runs:
using: "composite"
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Docker login if Docker registry is quay.io
if: ${{ inputs.docker_registry == 'quay.io' }}
uses: docker/login-action@v3
with:
registry: ${{ inputs.docker_registry }}
username: ${{ inputs.HMPPS_QUAYIO_USER }}
password: ${{ inputs.HMPPS_QUAYIO_TOKEN }}

- name: Docker login if Docker registry is ghcr.io
if: ${{ inputs.docker_registry == 'ghcr.io' }}
uses: docker/login-action@v3
with:
registry: ${{ inputs.docker_registry }}
username: ${{ github.actor }}
password: ${{ github.token }}

# - name: Configure AWS credentials
# if: ${{ inputs.docker_registry == 'ecr' }}
# uses: aws-actions/configure-aws-credentials@v2
# with:
# aws-access-key-id: ${{ secrets.AWS_MGMT_ECR_ID }}
# aws-secret-access-key: ${{ secrets.AWS_MGMT_ECR_KEY }}
# aws-region: eu-west-2

# - name: Login to Amazon ECR
# if: ${{ inputs.docker_registry == 'ecr' }}
# uses: aws-actions/amazon-ecr-login@v1

- name: Build Docker images
uses: docker/build-push-action@v6
with:
cache-from: type=gha
platforms: linux/amd64,linux/arm64
cache-to: type=gha,mode=max
context: .
push: ${{ inputs.push }}
provenance: false
build-args: |
"BUILD_NUMBER=${{ inputs.app_version }}"
"GIT_REF=${{ github.sha }}"
"GIT_BRANCH=${{ github.ref_name }}"
tags: |
${{ inputs.docker_registry}}/${{ inputs.registry_org }}/${{ github.event.repository.name }}:latest
${{ inputs.docker_registry}}/${{ inputs.registry_org }}/${{ github.event.repository.name }}:${{ inputs.app_version }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Cloud Platform Auth
description: Authenticate with MOJ Cloud Platform

inputs:
api:
description: The KUBE_ENV_API
required: true
cert:
description: The KUBE_CERT
required: true
cluster:
description: The KUBE_CLUSTER
required: true
namespace:
description: The KUBE_NAMESPACE
required: true
token:
description: The KUBE_TOKEN
required: true

runs:
using: composite
steps:
- name: Authenticate
shell: bash
run: |
echo "${{ inputs.cert }}" > ca.crt
kubectl config set-cluster ${{ inputs.cluster }} --certificate-authority=./ca.crt --server=${{ inputs.api }}
kubectl config set-credentials cd-serviceaccount --token=${{ inputs.token }}
kubectl config set-context ${{ inputs.cluster }} --cluster=${{ inputs.cluster }} --user=cd-serviceaccount --namespace=${{ inputs.namespace }}
kubectl config use-context ${{ inputs.cluster }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Cloud Platform Deploy
description: Deploy to Cloud Platform using Helm

inputs:
environment:
description: The environment to deploy to (dev/preprod/prod)
required: true
version:
description: The version of the service to deploy
required: true
api:
description: The KUBE_ENV_API
required: true
cert:
description: The KUBE_CERT
required: true
cluster:
description: The KUBE_CLUSTER
required: true
namespace:
description: The KUBE_NAMESPACE
required: true
token:
description: The KUBE_TOKEN
required: true
k8s_deployment_name:
description: "Kubernetes deployment name"
default: 'PROJECT_NAME'
required: false
changelog_git_paths:
default: ""
description: When set it will limit the file changes shown in the changelog to the specified paths only. This is useful for multi-project builds where otherwise it will show all changes from all projects.
required: false
show_changelog:
description: Whether the changelog should be sent by slack
required: false

outputs:
deployment_changelog:
description: "The changelog for the deployment"
value: ${{ steps.version_history.outputs.deployment_changelog }}

runs:
using: composite
steps:
- uses: actions/checkout@v4
- name: Authenticate
uses: ministryofjustice/hmpps-github-actions/.github/actions/build-test-and-deploy/cloud-platform-auth@v2 # WORKFLOW_VERSION
with:
api: ${{ inputs.api }}
cert: ${{ inputs.cert }}
cluster: ${{ inputs.cluster }}
namespace: ${{ inputs.namespace }}
token: ${{ inputs.token }}

- name: Get environment details
shell: bash
id: env
run: |
case ${{ inputs.environment }} in
'development') environment='dev' ;;
'preproduction') environment='preprod' ;;
'production') environment='prod' ;;
*) environment=${{ inputs.environment }} ;;
esac
echo "environment=${environment}" | tee -a "$GITHUB_OUTPUT"
- name: get version history
uses: ministryofjustice/hmpps-github-actions/.github/actions/version_history@v2 # WORKFLOW VERSION
if: ${{ inputs.show_changelog }}
id: version_history
with:
app_version: ${{ inputs.version }}
environment: ${{ inputs.environment }}
namespace: ${{ inputs.namespace }}
k8s_deployment_name: ${{ inputs.k8s_deployment_name }}
changelog_git_paths: ${{ inputs.changelog_git_paths }}

- name: Deploy
shell: bash
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew install helm
yq -i ".appVersion = \"${{ inputs.version }}\"" "helm_deploy/${{ github.event.repository.name }}/Chart.yaml"
helm dependency update "helm_deploy/${{ github.event.repository.name }}"
exec helm upgrade '${{ github.event.repository.name }}' 'helm_deploy/${{ github.event.repository.name }}' \
--atomic \
--history-max 10 \
--force \
--install \
--reset-values \
--set 'generic-service.image.tag=${{ inputs.version }}' \
--set 'version=${{ inputs.version }}' \
--timeout 10m \
--values 'helm_deploy/values-${{ steps.env.outputs.environment }}.yaml' \
--wait
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Create app version to use it for docker build and deploy pipelines
description: Create app version to use it for docker build and deploy pipelines

outputs:
version:
value: ${{ steps.create_version.outputs.version }}
description: this is what will be the version

runs:
using: composite
steps:
- name: create app version
id: create_version
shell: bash
run: |
version=$(date '+%Y-%m-%d').${{ github.run_number }}.$(echo ${{ github.sha }} | cut -c1-7)
echo "version=$version" >> $GITHUB_OUTPUT
Loading

0 comments on commit 8d538b8

Please sign in to comment.