Files
ota-admin-portal/.github/workflows/deploy.yml
Rafi Greenberg a5902f06b3 Docker-caching-and-better-slack-notifications (#102)
* test docker caching and slack

* try this

* this _might_ do it

* cleanup

* just realized this is running on self-hosted, so github cache doesn't make sense

* fix logging noise

* cache npm modules during test

* fiskerBot and icon

* quotes (just in case)
2021-11-05 09:09:04 -07:00

84 lines
2.7 KiB
YAML

on:
push:
branches:
- develop
- main
- "release/**"
- "hotfix/**"
jobs:
deploy:
name: Deploy
runs-on: self-hosted
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_CHANNEL: "#cloud-builds"
SLACK_FOOTER: "Powered by :fisker:"
SLACK_USERNAME: fiskerBot
SLACK_ICON: "https://github.com/Fisker-Inc.png?size=32"
TAG: ${{ github.sha }}
PROJECT: ota-admin-portal
steps:
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-west-2
- name: Create ECR Repo
run: aws ecr create-repository --region us-west-2 --repository-name ${PROJECT} || true
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Set Env
run: |
case ${GITHUB_REF} in
refs/heads/develop)
ENVIRONMENT=dev;;
refs/heads/release/*)
ENVIRONMENT=stg;;
refs/heads/hotfix/*)
ENVIRONMENT=stg;;
refs/heads/main)
ENVIRONMENT=prd;;
*)
ENVIRONMENT=dev;;
esac
echo "ENVIRONMENT=${ENVIRONMENT}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
build-args: ENVIRONMENT=${{ env.ENVIRONMENT }}
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT }}:${{ env.TAG}}-${{ env.ENVIRONMENT }}
cache-from: type=registry,ref=${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT }}:${{ env.TAG}}-${{ env.ENVIRONMENT }}
cache-to: type=inline
- name: Deploy
id: deploy
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |-
helm upgrade \
--kube-context $ENVIRONMENT \
--set image.registry=$REGISTRY \
--set image.name=$PROJECT \
--set image.tag=$TAG-$ENVIRONMENT \
--wait -i -f k8s/values-$ENVIRONMENT.yaml $PROJECT k8s/
- name: Notify if success
uses: rtCamp/action-slack-notify@v2
env:
MSG_MINIMAL: true
SLACK_MESSAGE: Successfully deployed to ${{ env.ENVIRONMENT }}!
if: ${{ success() }}
- name: Notify if failure
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: ${{ job.status }}
SLACK_MESSAGE: Job failed!
if: ${{ failure() }}