LASB-2748: Updated the docker tag to use the commit hash rather than … #73
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
# This workflow will build the image and deploy to the development environment using the tag in the BUILD_TAG.txt file. If the tag is the same as previous deploy, then no new build will take place | |
name: Build image and deploy to DEV | |
permissions: | |
id-token: write | |
contents: read | |
on: | |
push: | |
branches: | |
- '**' | |
- '!master' | |
jobs: | |
build-image: | |
runs-on: ubuntu-latest | |
outputs: | |
DOCKER_TAG: ${{ steps.get-docker-tag.outputs.DOCKER_TAG }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }} | |
aws-region: ${{ vars.ECR_REGION }} | |
- uses: aws-actions/amazon-ecr-login@v1 | |
id: login-ecr | |
- name: Determine Docker Tag | |
env: | |
REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
REPOSITORY: ${{ vars.ECR_REPOSITORY }} | |
id: get-docker-tag | |
run: | | |
DOCKER_TAG=$GITHUB_SHA | |
echo "Using docker tag '${DOCKER_TAG}'" | |
if docker pull "$REGISTRY/$REPOSITORY:${DOCKER_TAG}"; then | |
echo "Docker tag '${DOCKER_TAG}' already exists in the ECR - Not rebuilding Docker container" | |
else | |
echo >&2 "Docker tag '${DOCKER_TAG}' does not exist in the ECR - Application will be redeployed" | |
fi | |
echo "DOCKER_TAG=${DOCKER_TAG}" >> "$GITHUB_ENV" | |
echo "DOCKER_TAG=$DOCKER_TAG" >> "$GITHUB_OUTPUT" | |
- name: Building the NOLASA image | |
run: | | |
if docker pull "$REGISTRY/$REPOSITORY:$DOCKER_TAG"; then | |
echo "Docker image '$DOCKER_TAG' is up to date - not rebuilding" | |
else | |
echo "No Docker image for tag $DOCKER_TAG - Building the image with gradle ..." | |
chmod +x ./gradlew && ./gradlew build | |
echo Building the Docker image... | |
docker build -f Dockerfile_cp -t $REGISTRY/$REPOSITORY:$DOCKER_TAG --no-cache . | |
mkdir artifacts | |
zip -rq artifacts/buildreports.zip ./build/reports/tests/test/* | |
docker push $REGISTRY/$REPOSITORY:$DOCKER_TAG | |
fi | |
env: | |
REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
REPOSITORY: ${{ vars.ECR_REPOSITORY }} | |
- name: Upload build tags and test reports | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-reports | |
path: artifacts/ | |
deploy-application-dev: | |
environment: development | |
needs: build-image | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Authenticate to the Kubernetes cluster | |
env: | |
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} # K8s Cluster name needed defining as env for it to work | |
run: | | |
echo "${{ secrets.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=${{ secrets.KUBE_TOKEN }} | |
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${{ secrets.KUBE_NAMESPACE }} | |
kubectl config use-context ${KUBE_CLUSTER} | |
- name: Helm deploy to Development environment | |
run: | | |
cd helm_deploy/not-on-libra-auto-search-application | |
helm upgrade not-on-libra-auto-search-application -f values_dev.yaml . --namespace ${{ secrets.KUBE_NAMESPACE }} --install --set nolasa.image.tag=${{ needs.build-image.outputs.DOCKER_TAG }} --set nolasa.image.repository=754256621582.dkr.ecr.eu-west-2.amazonaws.com/${{ vars.ECR_REPOSITORY }} |