Skip to content

Merge pull request #338 from zooniverse/fem-redirect-correct-a-machine #43

Merge pull request #338 from zooniverse/fem-redirect-correct-a-machine

Merge pull request #338 from zooniverse/fem-redirect-correct-a-machine #43

name: Deploy HTTP Frontend Staging
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build_image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ghcr.io/zooniverse/http-frontend:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
test_configuration:
runs-on: ubuntu-latest
needs: build_image
name: Test nginx configuration
container: ghcr.io/zooniverse/http-frontend:${{ github.sha }}
steps:
- name: Test nginx config inside container
run: |
# Nginx prints on stderr, redirect to stdout
result=$(nginx -t 2>&1)
status=$(echo "$result" | grep failed | wc -l)
if [ $status -gt 0 ]; then
echo "Nginx configuration test failed"
echo "$result"
exit 1
else
echo "Nginx configuration test successful"
fi
push_latest_tag:
runs-on: ubuntu-latest
needs: test_configuration
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Tag tested image as latest
run: |
repo='ghcr.io/zooniverse/http-frontend'
docker pull $repo:${{ github.sha }}
docker tag $repo:${{ github.sha }} $repo:latest
docker push $repo:latest
deploy_nginx:
runs-on: ubuntu-latest
needs: push_latest_tag
steps:
- name: Set the target AKS cluster
uses: Azure/aks-set-context@v1
with:
creds: '${{ secrets.AZURE_AKS }}'
cluster-name: microservices
resource-group: kubernetes
- name: Checkout
uses: actions/checkout@v2
- name: Modify & apply template
run: |
sed "s/__IMAGE_TAG__/${{ github.sha }}/g" ./kubernetes/deployment-staging.tmpl \
| kubectl apply -f -
deploy_slack_notification:
name: Deploy Slack notification
uses: zooniverse/ci-cd/.github/workflows/slack_notification.yaml@main
needs: deploy_nginx
if: always()
with:
commit_id: ${{ github.sha }}
job_name: deploy_nginx
status: ${{ needs.deploy_nginx.result }}
title: "HTTP Frontend staging deploy complete"
title_link: "https://static-staging.zooniverse.org"
secrets:
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}