Skip to content

Build And Deploy

Build And Deploy #142

Workflow file for this run

name: Build And Deploy
on:
workflow_run:
workflows: ["Test"]
branches: [develop, main]
types:
- completed
env:
SERVICE_NAME: gnoswap-front
BRANCH_NAME: ${{ github.ref_name }}
jobs:
build-and-upload:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Notify on build start
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
channel-id: ${{ secrets.SLACK_CHANNEL }}
payload-file-path: "./.github/templates/slack-build-start.json"
- name: Setup
uses: ./.github/actions/setup
- name: Configure credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Push image
id: push-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
BRANCH_NAME: ${{ github.ref_name }}
ECR_REPOSITORY: gnoswap-front
run: |
docker build \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$BRANCH_NAME \
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
.
docker push --all-tags $ECR_REGISTRY/$ECR_REPOSITORY
- name: Notify on build failed
if: failure()
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
channel-id: ${{ secrets.SLACK_CHANNEL }}
payload-file-path: "./.github/templates/slack-build-fail.json"
# TODO: Migrating from EC2 to an ECS environment
deployment:
needs: build-and-upload
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_IP }}
port: ${{ secrets.REMOTE_PORT }}
username: ${{ secrets.REMOTE_SSH_ID }}
key: ${{ secrets.REMOTE_SSH_KEY }}
script: |
./deploy.sh ${{ env.SERVICE_NAME }} ${{ env.BRANCH_NAME }}
- name: Notify on deploy succeed
if: success()
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
channel-id: ${{ secrets.SLACK_CHANNEL }}
payload-file-path: "./.github/templates/slack-deploy-success.json"
- name: Notify on deploy failed
if: failure()
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
channel-id: ${{ secrets.SLACK_CHANNEL }}
payload-file-path: "./.github/templates/slack-deploy-fail.json"
# TODO: Discuss and decide to adopt Chromatic UI
# chromatic-deployment:
# needs: wait-on-tests
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Setup
# uses: ./.github/actions/setup
# - name: Push chromatic UI
# uses: chromaui/action@v1
# with:
# projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN_2 }}
# workingDir: packages/web