Skip to content

Commit

Permalink
Move default deployment from Azure Pipelines to GitHub Actions (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell committed Mar 7, 2024
1 parent 0114e4f commit c9e35aa
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 134 deletions.
68 changes: 62 additions & 6 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ on:
- ".github/workflows/server.yml"
- "!docs/**"

concurrency:
group: ${{ github.workflow }}

env:
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }}

jobs:
Build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -71,6 +78,34 @@ jobs:
cp ${{ github.workspace }}/server/main.bicep ${{ github.workspace }}/drop/main.bicep && \
az bicep build --file server/main.bicep --outfile ${{ github.workspace }}/drop/main.json
- name: Publish Artifact
uses: actions/upload-artifact@v4
with:
path: ${{ github.workspace }}/drop/*
name: drop

- name: Create deploy folder
run: |
mkdir -p deploy
cp ${{ github.workspace }}/server/main.bicep ${{ github.workspace }}/deploy/main.bicep
cp ${{ github.workspace }}/server/main.parameters.json ${{ github.workspace }}/deploy/main.parameters.json
- name: Replace tokens in deploy folder
uses: cschleiden/replace-tokens@v1
with:
files: '["${{ github.workspace }}/deploy/main.parameters.json"]'
env:
DOCKER_IMAGE_TAG: ${{ steps.gitversion.outputs.shortSha }}
DEPENDABOT_PROJECT_TOKEN: ${{ secrets.DEPENDABOT_PROJECT_TOKEN }}
DEPENDABOT_GITHUB_TOKEN: ${{ secrets.DEPENDABOT_GITHUB_TOKEN }}

- name: Publish deploy artifact
uses: actions/upload-artifact@v4
with:
path: deploy
name: deploy
retention-days: 1

- name: Pull Docker base image & warm Docker cache
run: docker pull "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest"

Expand Down Expand Up @@ -112,12 +147,6 @@ jobs:
docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.major }}.${{ steps.gitversion.outputs.minor }}"
docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.major }}"
- name: Publish Artifact
uses: actions/upload-artifact@v4
with:
path: ${{ github.workspace }}/drop/*
name: drop

- name: Upload Release
if: startsWith(github.ref, 'refs/tags/')
uses: ncipollo/release-action@v1
Expand All @@ -128,3 +157,30 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
allowUpdates: true


Deploy:
runs-on: ubuntu-latest
needs: Build
if: ${{ github.actor != 'dependabot[bot]' && ((github.ref == 'refs/heads/main') || startsWith(github.ref, 'refs/tags')) }}

steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: deploy
path: ${{ github.workspace }}/deploy

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

- name: Deploy
uses: azure/arm-deploy@v2
with:
subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
resourceGroupName: ${{ env.AZURE_RESOURCE_GROUP }}
template: '${{ github.workspace }}/deploy/main.bicep'
parameters: '${{ github.workspace }}/deploy/main.parameters.json'
scope: 'resourcegroup'
125 changes: 0 additions & 125 deletions azure-pipelines.yml

This file was deleted.

6 changes: 3 additions & 3 deletions server/main.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"value": "dependabot"
},
"projectSetups": {
"value": "[{\"url\":\"#{System_TeamFoundationCollectionUri}##{System_TeamProject}#\", \"token\":\"#{DependabotProjectToken}#\",\"AutoComplete\":true}]"
"value": "[{\"url\":\"https://dev.azure.com/tingle/\", \"token\":\"#{DEPENDABOT_PROJECT_TOKEN}#\",\"AutoComplete\":true}]"
},
"githubToken": {
"value": "#{GithubToken}#"
"value": "#{DEPENDABOT_GITHUB_TOKEN}#"
},
"imageTag": {
"value": "#{GITVERSION_SHORTSHA}#"
"value": "#{DOCKER_IMAGE_TAG}#"
}
}
}

0 comments on commit c9e35aa

Please sign in to comment.