Merge pull request #586 from SierraSoftworks/dependabot/terraform/inf… #277
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: Deploy | |
on: | |
push: | |
branches: [ main ] | |
paths-ignore: | |
- "docs/**" | |
pull_request: | |
branches: [ main ] | |
permissions: | |
id-token: write | |
packages: write | |
env: | |
CARGO_TERM_COLOR: always | |
HANDLER_NAME: bender | |
IMAGE: sierrasoftworks/bender | |
STAGING_DEPLOYMENT_APP_ID: 65d7542d-354d-4129-898c-8848be8d5ecd | |
STAGING_FUNCTION_NAME: bender-sierrasoftworks-staging | |
STAGING_HEALTHCHECK: "https://bender-staging.sierrasoftworks.com/api/v1/health" | |
LIVE_DEPLOYMENT_APP_ID: 5d3fdb10-30ca-4aaa-9128-17101a1ac349 | |
LIVE_FUNCTION_NAME: bender-sierrasoftworks | |
LIVE_HEALTHCHECK: "https://bender.sierrasoftworks.com/api/v1/health" | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build Dockerfile | |
run: docker build . --file Dockerfile --tag image | |
- run: | | |
docker run --rm -t -v $PWD:/volume image cp /app/$HANDLER_NAME /volume/handler | |
mv ./handler ./$HANDLER_NAME | |
- name: Save handler artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.HANDLER_NAME }} | |
path: ${{ env.HANDLER_NAME }} | |
- name: Log into registries | |
if: github.event_name == 'push' | |
run: | | |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin | |
echo "${{ secrets.DOCKER_HUB }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | |
- name: Calculate version number | |
id: version | |
if: github.event_name == 'push' | |
run: | | |
VERSION=$(git describe --tags 2>/dev/null || git rev-parse --short HEAD) | |
echo "::set-output name=version::$VERSION" | |
- name: Push image to GitHub | |
if: github.event_name == 'push' | |
run: | | |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/${{ github.event.repository.name }} | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
docker tag image $IMAGE_ID:latest | |
docker push $IMAGE_ID:latest | |
docker tag image $IMAGE_ID:${{ steps.version.outputs.version }} | |
docker push $IMAGE_ID:${{ steps.version.outputs.version }} | |
- name: Push image to Docker Hub | |
if: github.event_name == 'push' | |
run: | | |
IMAGE_ID=${{ env.IMAGE }} | |
echo IMAGE_ID=$IMAGE_ID | |
docker tag image $IMAGE_ID:latest | |
docker push $IMAGE_ID:latest | |
docker tag image $IMAGE_ID:${{ steps.version.outputs.version }} | |
docker push $IMAGE_ID:${{ steps.version.outputs.version }} | |
deploy-staging: | |
needs: build | |
runs-on: ubuntu-20.04 | |
if: github.actor != 'dependabot[bot]' | |
environment: | |
name: Staging | |
url: ${{ env.STAGING_HEALTHCHECK }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Fetch handler artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.HANDLER_NAME }} | |
- name: 'Login via Azure CLI' | |
uses: azure/login@v1 | |
with: | |
tenant-id: a26571f1-22b3-4756-ac7b-39ca684fab48 | |
subscription-id: 108b3ddb-53fb-4344-80b2-d6c151912be6 | |
client-id: ${{ env.STAGING_DEPLOYMENT_APP_ID }} | |
- name: 'Run Azure Functions Action' | |
uses: Azure/functions-action@v1 | |
with: | |
app-name: ${{ env.STAGING_FUNCTION_NAME }} | |
respect-funcignore: 'true' | |
healthcheck-staging: | |
needs: deploy-staging | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Probe | |
uses: Jtalk/url-health-check-action@v3 | |
with: | |
url: ${{ env.STAGING_HEALTHCHECK }} | |
max-attempts: 5 | |
retry-delay: 10s | |
follow-redirect: true | |
deploy-live: | |
needs: healthcheck-staging | |
if: github.event_name == 'push' | |
environment: | |
name: Production | |
url: ${{ env.LIVE_HEALTHCHECK }} | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Fetch handler artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.HANDLER_NAME }} | |
- name: 'Login via Azure CLI' | |
uses: azure/login@v1 | |
with: | |
tenant-id: a26571f1-22b3-4756-ac7b-39ca684fab48 | |
subscription-id: 108b3ddb-53fb-4344-80b2-d6c151912be6 | |
client-id: ${{ env.LIVE_DEPLOYMENT_APP_ID }} | |
- name: 'Run Azure Functions Action' | |
uses: Azure/functions-action@v1 | |
with: | |
app-name: ${{ env.LIVE_FUNCTION_NAME }} | |
respect-funcignore: 'true' | |
healthcheck-live: | |
needs: deploy-live | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Probe | |
uses: Jtalk/url-health-check-action@v3 | |
with: | |
url: ${{ env.LIVE_HEALTHCHECK }} | |
max-attempts: 5 | |
retry-delay: 10s | |
follow-redirect: true |