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)
This commit is contained in:
Rafi Greenberg
2021-11-05 09:09:04 -07:00
committed by GitHub
parent 16c3e2902b
commit a5902f06b3
4 changed files with 95 additions and 57 deletions

View File

@@ -3,23 +3,24 @@ on:
branches:
- develop
- main
- 'release/**'
- 'hotfix/**'
- "release/**"
- "hotfix/**"
jobs:
deploy:
name: Deploy
runs-on: self-hosted
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
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 Notify
uses: act10ns/slack@master
with:
channel: "#cloud-builds"
status: starting
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS Credentials
@@ -33,26 +34,30 @@ jobs:
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: Build, tag, and push image to Amazon ECR
id: build-tag-push-image
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker build --build-arg ENVIRONMENT=$ENVIRONMENT -t $REGISTRY/$PROJECT:$TAG-$ENVIRONMENT .
docker push $REGISTRY/$PROJECT:$TAG-$ENVIRONMENT
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:
@@ -64,9 +69,15 @@ jobs:
--set image.name=$PROJECT \
--set image.tag=$TAG-$ENVIRONMENT \
--wait -i -f k8s/values-$ENVIRONMENT.yaml $PROJECT k8s/
- uses: act10ns/slack@master
with:
channel: "#cloud-builds"
status: ${{ job.status }}
message: Successfully deployed to ${{ env.ENVIRONMENT }}!
if: always()
- 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() }}

View File

@@ -4,21 +4,17 @@ on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build --if-present
- run: npm test
env:
CI: true
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: "14"
cache: "npm"
- run: npm install
- run: npm run build --if-present
- run: npm test
env:
CI: true