Build, push and deploy site #2244
Workflow file for this run
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: Build, push and deploy site | |
on: | |
push: | |
tags: | |
- '*' | |
branches: | |
- main | |
workflow_dispatch: | |
env: | |
OHIO_SITE_IMAGE: quay.io/operator-framework/operatorhubio | |
OHIO_REGISTRY_IMAGE: quay.io/operator-framework/upstream-community-operators | |
SOURCE_BRANCH: ${{ github.ref }} | |
jobs: | |
build: | |
name: Build site image | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [16] | |
steps: | |
- name: Setup environment using Docker | |
run: | | |
if [[ $SOURCE_BRANCH == *"refs/tags"* ]]; then | |
docker run -d -p 50051:50051 --name registry $OHIO_REGISTRY_IMAGE:latest | |
else | |
docker run -d -p 50051:50051 --name registry $OHIO_REGISTRY_IMAGE:dev | |
fi | |
docker ps | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Build server app using Nodejs | |
run: | | |
docker ps | |
cd server | |
npm install | |
npm run build-only | |
rm -rd node_modules | |
- name: Build site image | |
run: | | |
export OHIO_SITE_TAG=$(bash -c ' | |
if [[ $SOURCE_BRANCH == *"refs/tags"* ]]; then | |
echo v4; | |
else | |
echo $SOURCE_BRANCH | cut -d "/" -f 3; | |
fi | |
') | |
docker build -t "$OHIO_SITE_IMAGE:$OHIO_SITE_TAG" -f travis.Dockerfile . | |
- name: Push new site image | |
if: ${{ contains(github.ref, 'refs/tags') || github.ref == 'refs/heads/main' }} | |
run: | | |
export OHIO_SITE_TAG=$(bash -c ' | |
if [[ $SOURCE_BRANCH == *"refs/tags"* ]]; then | |
echo v4; | |
else | |
echo $SOURCE_BRANCH | cut -d "/" -f 3; | |
fi | |
') | |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin $DOCKER_REGISTRY | |
docker push "$OHIO_SITE_IMAGE:$OHIO_SITE_TAG" | |
env: | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }} | |
deploy: | |
name: Deploy site | |
needs: build | |
runs-on: ubuntu-latest | |
env: | |
OPENSHIFT_SERVER: ${{ secrets.OPENSHIFT_SERVER }} | |
OPENSHIFT_TOKEN_DEV: ${{ secrets.OPENSHIFT_TOKEN_DEV }} | |
OPENSHIFT_TOKEN_PREPROD: ${{ secrets.OPENSHIFT_TOKEN_PREPROD }} | |
OPENSHIFT_TOKEN_PROD: ${{ secrets.OPENSHIFT_TOKEN_PROD }} | |
AKAMAI_SECRETS: ${{ secrets.AKAMAI_SECRETS }} | |
AKAMAI_APPCODES: ${{ secrets.AKAMAI_APPCODES }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Deploy to DEV | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
./deploy.sh dev | |
- name: Deploy to PREPROD | |
if: ${{ contains(github.ref, 'refs/tags') }} | |
run: | | |
./deploy.sh preprod | |
- name: Deploy to PROD | |
if: ${{ contains(github.ref, 'refs/tags') }} | |
run: | | |
./deploy.sh prod | |
- name: Invalidate Akamai cache | |
if: ${{ contains(github.ref, 'refs/tags') }} | |
run: | | |
./invalidate.sh | |
slack-notification: | |
name: "Slack notification" | |
needs: [ build, deploy ] | |
if: failure() | |
runs-on: ubuntu-latest | |
steps: | |
- name: Report Status | |
uses: ravsamhq/notify-slack-action@master | |
with: | |
notification_title: 'Operatorhub.io deploy failed: ${{ needs.pr-check.outputs.opp_pr_title }}' | |
footer: 'monitoring' | |
# status: ${{ needs.pr-check.result }} | |
status: 'failure' | |
notify_when: 'failure' | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }} | |
continue-on-error: true |