generated from pagopa/template-java-microservice
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c0ce99
commit 289f82d
Showing
1 changed file
with
11 additions
and
75 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,18 +14,15 @@ on: | |
|
||
env: | ||
TEMPLATE_DIR: azure-dashboard | ||
DOCKER_IMAGE_TAG: sha256:04d8ead53c772d23b094c2a395292dc159e6f2905e1b13b5f828f31eac6eb27f | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
deployments: write | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
dashboard: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-22.04 | ||
|
||
strategy: | ||
matrix: | ||
environment: [prod] | ||
|
@@ -36,89 +33,28 @@ jobs: | |
steps: | ||
- name: Checkout | ||
id: checkout | ||
# from https://github.com/actions/checkout/commits/main | ||
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707 | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | ||
with: | ||
persist-credentials: false | ||
fetch-depth: 0 | ||
|
||
- name: Read terraform version | ||
id: read-version | ||
shell: bash | ||
run: | | ||
echo "TERRAFORM_VERSION=`cat .terraform-version`" >> $GITHUB_ENV | ||
- name: Setup Terraform | ||
# from https://github.com/hashicorp/setup-terraform/commits/main | ||
uses: hashicorp/setup-terraform@8feba2b913ea459066180f9cb177f58a881cf146 | ||
uses: hashicorp/setup-terraform@69c00852f1304c321337f45a105731218c2d5544 | ||
with: | ||
terraform_version: ${{ env.TERRAFORM_VERSION }} | ||
|
||
- name: Login | ||
id: login | ||
# from https://github.com/Azure/login/commits/master | ||
uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 | ||
- uses: pagopa/opex-dashboard-azure-action@3ad80a5e4a2d5a8f342615637072f21b687320ce | ||
with: | ||
client-id: ${{ secrets.CLIENT_ID }} | ||
environment: ${{ matrix.environment }} | ||
api-name: ${{ matrix.product }} | ||
config: .opex/${{ matrix.product }}/env/${{ matrix.environment }}/config.yaml | ||
client-id: ${{ secrets.CLIENT_ID }} ??? | ||
tenant-id: ${{ secrets.TENANT_ID }} | ||
subscription-id: ${{ secrets.SUBSCRIPTION_ID }} | ||
|
||
# this action create a folder named /azure-dashboard | ||
- uses: pagopa/[email protected] | ||
with: | ||
template: ${{ env.TEMPLATE_DIR }} | ||
config: .opex/${{ matrix.product }}/env/${{ matrix.environment }}/config.yaml | ||
|
||
# we need to set env variables in the folder /azure-dashboard | ||
- name: Copy Environments | ||
run: | | ||
cp -R .opex/${{ matrix.product }}/env ./${TEMPLATE_DIR} | ||
# now is possible to launch the command: terraform apply | ||
- name: Terraform Apply | ||
shell: bash | ||
run: | | ||
cd ./${TEMPLATE_DIR} | ||
export ARM_CLIENT_ID="${{ secrets.CLIENT_ID }}" | ||
export ARM_SUBSCRIPTION_ID=$(az account show --query id --output tsv) | ||
export ARM_TENANT_ID=$(az account show --query tenantId --output tsv) | ||
export ARM_USE_OIDC=true | ||
bash ./terraform.sh apply ${{ matrix.environment }} -auto-approve | ||
delete_github_deployments: | ||
runs-on: ubuntu-latest | ||
needs: dashboard | ||
if: ${{ always() }} | ||
steps: | ||
- name: Dump GitHub context | ||
env: | ||
GITHUB_CONTEXT: ${{ toJSON(github) }} | ||
run: echo "$GITHUB_CONTEXT" | ||
|
||
- name: Delete Previous deployments | ||
uses: actions/github-script@v6 | ||
env: | ||
SHA_HEAD: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.sha) || github.sha}} | ||
with: | ||
script: | | ||
const { SHA_HEAD } = process.env | ||
const deployments = await github.rest.repos.listDeployments({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
sha: SHA_HEAD | ||
}); | ||
await Promise.all( | ||
deployments.data.map(async (deployment) => { | ||
await github.rest.repos.createDeploymentStatus({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
deployment_id: deployment.id, | ||
state: 'inactive' | ||
}); | ||
return github.rest.repos.deleteDeployment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
deployment_id: deployment.id | ||
}); | ||
}) | ||
); | ||
docker-version: ${{ env.DOCKER_IMAGE_TAG }} |