Login through alternative method because terraform didn't like it #93
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: CI/CD Microservices | |
on: | |
pull_request: | |
types: | |
- "opened" | |
- "reopened" | |
- "synchronize" | |
- "closed" | |
branches: [main, development] | |
release: | |
types: [created] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} | |
cancel-in-progress: true | |
jobs: | |
changes: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: read | |
outputs: | |
apps: ${{ steps.filter.outputs.changes }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
token: ${{ github.token }} | |
filters: | | |
accounts: | |
- "apps/accounts/**" | |
advertisements: | |
- "apps/advertisements/**" | |
gateway: | |
- "apps/gateway/**" | |
config-changes: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: read | |
outputs: | |
changes: ${{ steps.filter.outputs.changes }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
token: ${{ github.token }} | |
filters: | | |
k8s: | |
- "k8s/**" | |
workflows: | |
- ".github/workflows/**" | |
terraform: | |
- "main.tf" | |
lint: | |
runs-on: ubuntu-latest | |
needs: changes | |
if: needs.changes.outputs.apps != '[]' | |
strategy: | |
matrix: | |
app: ${{ fromJSON(needs.changes.outputs.apps) }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
cache: npm | |
- name: Install Node.js dependencies | |
run: npm ci -w apps/${{ matrix.app }} | |
- name: Run linters ${{ matrix.app }} | |
run: npm run lint -w apps/${{ matrix.app }} --if-present | |
test: | |
runs-on: ubuntu-latest | |
needs: changes | |
if: needs.changes.outputs.apps != '[]' | |
strategy: | |
matrix: | |
app: ${{ fromJSON(needs.changes.outputs.apps) }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
cache: npm | |
- name: Install Node.js dependencies | |
run: npm ci -w apps/${{ matrix.app }} | |
- name: Run Tests ${{ matrix.app }} | |
run: npm run test -w apps/${{ matrix.app }} --if-present | |
build: | |
needs: [changes, config-changes, lint, test] | |
if: (github.event_name == 'release' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)) && (needs.changes.outputs.apps != '[]' || needs.config-changes.outputs.configs != '[]') | |
runs-on: ubuntu-latest | |
environment: production | |
strategy: | |
matrix: | |
app: ${{ fromJSON(needs.changes.outputs.apps) }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Azure Login | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Build image on ACR | |
uses: azure/CLI@v1 | |
with: | |
inlineScript: | | |
az configure --defaults acr=${{ vars.AZURE_CONTAINER_REGISTRY }} | |
az acr build -t ${{ vars.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ vars.AZURE_PROJECT_NAME }}-${{ matrix.app }}:latest -r ${{ vars.AZURE_CONTAINER_REGISTRY }} ./apps/${{ matrix.app }}/ | |
deploy: | |
needs: build | |
if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && (github.event_name == 'release' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)) | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Azure Login | |
uses: azure/CLI@v1 | |
id: login | |
with: | |
inlineScript: | | |
az login --service-principal -u ${{ vars.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }} | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: 1.6.6 | |
- name: Terraform Init | |
run: terraform init | |
- name: Terraform Apply | |
run: | | |
terraform apply -auto-approve -input=false \ | |
-var="db_admin_user=${{ secrets.DB_ADMIN_USER }}" \ | |
-var="db_admin_password=${{ secrets.DB_ADMIN_PASSWORD }}" | |
- name: Gets K8s context | |
id: context | |
uses: azure/aks-set-context@v3 | |
with: | |
resource-group: ${{ vars.AZURE_RESOURCE_GROUP }} | |
cluster-name: ${{ vars.AZURE_CLUSTER_NAME }} | |
- name: Set secrets | |
run: | | |
kubectl create secret generic account-service-secrets \ | |
--from-literal=DATABASE_HOST="$(terraform output -raw accounts_database_host)" \ | |
--from-literal=DATABASE_NAME="$(terraform output -raw accounts_database_name)" \ | |
--from-literal=DATABASE_PASSWORD="$(terraform output -raw accounts_database_password)" \ | |
--from-literal=DATABASE_PORT="$(terraform output -raw accounts_database_port)" \ | |
--from-literal=DATABASE_USER="$(terraform output -raw accounts_database_user)" | |
kubectl create secret generic advertisement-service-secrets \ | |
--from-literal=DATABASE_HOST="$(terraform output -raw accounts_database_host)" \ | |
--from-literal=DATABASE_NAME="$(terraform output -raw accounts_database_name)" \ | |
--from-literal=DATABASE_PASSWORD="$(terraform output -raw accounts_database_password)" \ | |
--from-literal=DATABASE_PORT="$(terraform output -raw accounts_database_port)" \ | |
--from-literal=DATABASE_USER="$(terraform output -raw accounts_database_user)" | |
- name: Deploys application | |
uses: Azure/k8s-deploy@v4 | |
with: | |
manifests: | | |
k8s/gateway-ingress.yml | |
k8s/gateway-deployment.yml | |
k8s/account-deployment.yml | |
k8s/advertisement-deployment.yml | |
k8s/message-queue-deployment.yml | |
images: | | |
${{ vars.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ vars.AZURE_PROJECT_NAME }}-gateway:latest | |
${{ vars.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ vars.AZURE_PROJECT_NAME }}-accounts:latest | |
${{ vars.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ vars.AZURE_PROJECT_NAME }}-advertisements:latest | |
imagepullsecrets: | | |
${{ vars.PROJECT_NAME }} |