✨Add workflow to build and deploy app #10
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy (POC) | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
env: | |
KUBE_CLUSTER: ${{ secrets.DEV_KUBE_CLUSTER }} | |
KUBE_NAMESPACE: ${{ secrets.DEV_KUBE_NAMESPACE }} | |
KUBE_CERT: ${{ secrets.DEV_KUBE_CERT }} | |
KUBE_TOKEN: ${{ secrets.DEV_KUBE_TOKEN }} | |
ECR_REGISTRY: ${{ vars.ECR_REGISTRY }} | |
ECR_REPOSITORY: ${{ vars.DEVELOPMENT_ECR_REPOSITORY }} | |
IMAGE_TAG: ${{ vars.ECR_REGISTRY }}/${{ vars.DEVELOPMENT_ECR_REPOSITORY }}:${{ github.sha }} | |
jobs: | |
build-push: | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.DEVELOPMENT_ECR_ROLE_TO_ASSUME }} | |
aws-region: eu-west-2 | |
- uses: aws-actions/amazon-ecr-login@v2 | |
- run: | | |
docker build -t ${IMAGE_TAG} . | |
docker push ${IMAGE_TAG} | |
deploy-to-dev: | |
needs: build-push | |
runs-on: ubuntu-latest | |
container: alpine/k8s:1.23.17 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Authenticate to the cluster | |
run: | | |
echo "${KUBE_CERT}" > ca.crt | |
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER} | |
kubectl config set-credentials deploy-user --token=${KUBE_TOKEN} | |
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE} | |
kubectl config get-contexts | |
kubectl config use-context ${KUBE_CLUSTER} | |
- name: Helm install | |
run: | | |
helm upgrade operations-engineering-metadata-poc \ | |
helm/operations-engineering-metadata-poc \ | |
--install \ | |
--force \ | |
--wait \ | |
--timeout 10m \ | |
--namespace ${KUBE_NAMESPACE} \ | |
--set image.tag=${{ github.sha }} \ | |
-f helm/operations-engineering-metadata-poc/values.yaml \ | |
-f helm/operations-engineering-metadata-poc/values-poc.yaml |