Skip to content

CD

CD #11

Workflow file for this run

name: CD
on:
workflow_dispatch:
inputs:
image_tag:
description: 'The image tag for deployment'
required: true
type: string
env:
DOCKER_IMAGE: ${{ github.event.inputs.image_tag }}
TF_TOKEN_app_terraform_io: ${{ secrets.TERRAFORM_TOKEN }}
SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
DJANGO_KEY: ${{ secrets.DJANGO_KEY }}
DJANGO_HOSTS: ${{ vars.DJANGO_HOSTS }}
DJANGO_CSRF: ${{ vars.DJANGO_CSRF }}
DJANGO_STATIC: ${{ vars.DJANGO_STATIC }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
jobs:
prepare-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
- name: Set up CDK for Terraform
run: |
pip install --user pipenv
npm install -g cdktf-cli
- name: cdktf synth
run: |
pipenv install
cdktf synth
working-directory: cdktf
- name: Make Terraform plan
run: |
terraform init
terraform plan -out=tfplan
working-directory: cdktf/cdktf.out/stacks/urlshortener-stack
- name: Show Terraform plan
run: terraform show tfplan
working-directory: cdktf/cdktf.out/stacks/urlshortener-stack
- name: Upload plan as artifact
uses: actions/upload-artifact@v4
with:
name: cdktf
path: cdktf
deploy:
needs: prepare-deploy
runs-on: ubuntu-latest
environment: 'main'
steps:
- name: Download plan artifact
uses: actions/download-artifact@v4
with:
name: cdktf
path: ./
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
- name: Deploy
run: |
terraform init
terraform apply tfplan
working-directory: cdktf.out/stacks/urlshortener-stack
- name: Upload static files
run: sh swa.sh ${{ github.event.inputs.image_tag }}