Build and deploy docker image #4
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 docker image | |
on: | |
workflow_dispatch: # Allows manual workflow trigger | |
repository_dispatch: # Allows API workflow trigger | |
types: [Build backend request from Chewie] | |
# Triggers the workflow on pull request events but only for the "main" branch | |
# pull_request: | |
# branches: [ "main" ] | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | |
AWS_REGION: eu-west-2 | |
ECR_REPOSITORY: app-backend | |
IMAGE_TAG: ${{ github.event.client_payload.COMMIT_HASH != null && github.event.client_payload.COMMIT_HASH || github.sha }} | |
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} | |
KUBE_NAMESPACE: default | |
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
jobs: | |
buildDeploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Cancel Previous Runs | |
uses: styfle/[email protected] | |
with: | |
access_token: ${{ github.token }} | |
- name: Echo Env Vars through Context | |
run: | | |
echo "$GITHUB_CONTEXT" | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
context: ${{ github.workspace }} | |
file: ./Dockerfile | |
push: true | |
tags: ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/app-backend:${{ env.IMAGE_TAG }} | |
- name: Deploy to Kubernetes cluster | |
uses: kodermax/kubectl-aws-eks@master | |
env: | |
RELEASE_IMAGE: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | |
with: | |
args: set image deployment/app-qa-network-100 app-backend=${{ env.RELEASE_IMAGE }} --record -n $KUBE_NAMESPACE | |
- name: Verify Kubernetes deployment | |
uses: kodermax/kubectl-aws-eks@master | |
with: | |
args: rollout status deployment/app-qa-network-100 -n $KUBE_NAMESPACE | |
- uses: sarisia/actions-status-discord@v1 | |
if: always() | |
with: | |
webhook: ${{ env.DISCORD_WEBHOOK }} |