Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use shared dev deploy workflow in operations #1092

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 12 additions & 86 deletions .github/workflows/build-and-deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -1,95 +1,21 @@
# This workflow will build a docker image, push it to ghcr.io, and deploy it to an Azure WebApp.
name: Build and Deploy to dev service app
name: Build and Deploy -- DEV

# Update the triggers based on the environment that is being deployed to.
# Triggers for dev deployments: 1) manually triggered, 2) push to branch `master`
# Triggers for prod deployments: 1) manually triggered, 2) release created
on:
workflow_dispatch:
push:
branches: [master]

# There are secrets and environment variables that need to be set that control what is pushed to
# ghcr and Azure.
#
# Secrets:
# AZURE_CREDENTIALS: service principal that has access to the Azure WebApp
# AZURE_WEBAPP_PUBLISH_PROFILE_DEV: publish profile for the Azure WebApp NOTE: The name of the secret changes. For dev, it ends in `_DEV`. Production does not have an extension.
#
# Environment Variables:
# APPLICATION_TYPE: type of application that is being deployed; used to add a label to the Docker image (values: api | web | worker)
# AZURE_WEBAPP_NAME: name of the Azure WebApp being deployed
# DEPLOY_ENVIRONMENT: environment that the code is being deployed to; used to add a label to the Docker image (values: dev | prod)
# DEPLOY_DOCKER_TAG: the tag used for deploying a specific Docker image to Azure. For dev, use the `github.sha`. For production, use the SEMVER
# version of the release. Make sure to add this tag to the `DOCKER_TAGS` in the `Build and push Docker image` step.
# DOCKER_IMAGE_NAME: name of the Docker image that is being built and pushed to ghcr.io.

env:
APPLICATION_TYPE: api
AZURE_WEBAPP_NAME: clearlydefined-api-dev
DEPLOY_ENVIRONMENT: dev
DEPLOY_DOCKER_TAG: ${{ github.sha }}
DOCKER_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.repository }}-dev

jobs:
build-and-deploy:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Log into ghcr registry
uses: docker/login-action@v3.1.0
with:
registry: ghcr.io
username: ${{ github.actor }} # user that kicked off the action
password: ${{ secrets.GITHUB_TOKEN }} # token created when the action launched (short lived)

- name: Build and push Docker image
env:
DOCKER_TAGS: |
${{ env.DOCKER_IMAGE_NAME }}:${{ env.DEPLOY_DOCKER_TAG }}
uses: docker/build-push-action@v5.3.0
with:
context: .
push: true
file: Dockerfile
tags: ${{ env.DOCKER_TAGS }}
labels: |
env=${{ env.DEPLOY_ENVIRONMENT }}
type=${{ env.APPLICATION_TYPE }}

- name: Login for Azure cli commands
uses: azure/login@v2.1.0
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Set DOCKER configs in Azure web app
uses: azure/appservice-settings@v1.1.1
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
app-settings-json: |
[
{
"name": "DOCKER_CUSTOM_IMAGE_NAME",
"value": "${{ env.DOCKER_IMAGE_NAME }}:${{ env.DEPLOY_DOCKER_TAG }}",
"slotSetting": false
},
{
"name": "DOCKER_REGISTRY_SERVER_URL",
"value": "https://ghcr.io",
"slotSetting": false
},
{
"name": "BUILD_SHA",
"value": "${{ github.sha }}",
"slotSetting": false
}
]

- name: Deploy to Azure WebApp
uses: azure/webapps-deploy@v3.0.1
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_DEV }}
images: '${{ env.DOCKER_IMAGE_NAME }}:${{ env.DEPLOY_DOCKER_TAG }}'
uses: clearlydefined/operations/.github/workflows/app-build-and-deploy.yml@v1.0.0
secrets:
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
AZURE_WEBAPP_PUBLISH_PROFILE: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_DEV }}
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
PRODUCTION_DEPLOYERS: ${{ secrets.PRODUCTION_DEPLOYERS }}
with:
deploy-env: dev
application-type: api
azure-app-base-name: clearlydefined-api
azure-app-name-postfix: -dev
36 changes: 36 additions & 0 deletions .github/workflows/build-and-deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will build a docker image, push it to ghcr.io, and deploy it to an Azure WebApp.
name: Build and Deploy -- PROD

on:
workflow_dispatch:
release:
types: [published]

jobs:
determine-trigger:
name: Determine if this was triggered by a release or workflow_dispatch
runs-on: ubuntu-latest
outputs:
is-release: ${{ env.IS_RELEASE }}
steps:
- name: Check if this was triggered by a release
id: release
run: |
echo "IS_RELEASE"=${{ github.event_name == 'release' }} >> $GITHUB_ENV

build-and-deploy-prod:
uses: clearlydefined/operations/.github/workflows/app-build-and-deploy.yml@v1.0.0
needs: determine-trigger
secrets:
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
AZURE_WEBAPP_PUBLISH_PROFILE: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_PROD }}
AZURE_SECONDARY_WEBAPP_PUBLISH_PROFILE: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_PROD_EU }}
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
PRODUCTION_DEPLOYERS: ${{ secrets.PRODUCTION_DEPLOYERS }}
with:
deploy-env: prod
application-type: api
azure-app-base-name: clearlydefined-api
azure-app-name-postfix: -prod
secondary-azure-app-name-postfix: -prod-europe
is-release: ${{ needs.determine-trigger.outputs.is-release }}
148 changes: 0 additions & 148 deletions .github/workflows/build_and_deploy_prod.yml

This file was deleted.

2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function createApp(config) {

app.use(require('./middleware/querystring'))

app.use('/', require('./routes/index')(config.buildsha))
app.use('/', require('./routes/index')(config.buildsha, config.appVersion))
app.use('/origins/github', require('./routes/originGitHub')())
app.use('/origins/crate', require('./routes/originCrate')())
app.use('/origins/conda', require('./routes/originConda')())
Expand Down
1 change: 1 addition & 0 deletions bin/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ module.exports = {
crawlerId: config.get('APPINSIGHTS_CRAWLER_APPLICATIONID'),
crawlerKey: config.get('APPINSIGHTS_CRAWLER_APIKEY')
},
appVersion: config.get('APP_VERSION'),
buildsha: config.get('BUILD_SHA')
}
6 changes: 4 additions & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ const express = require('express')
const router = express.Router()

router.get('/', function (req, res) {
const msg = `{ "status": "OK", "sha": "${sha}" }`
const msg = `{ "status": "OK", "version": "${version}", "sha": "${sha}"`
res.status(200).send(msg)
})

module.exports = router

let version
let sha
function setup(buildsha) {
function setup(buildsha, appVersion) {
version = appVersion
sha = buildsha
return router
}
Expand Down
Loading