Attempt to fix gh workflow #80
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.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 | |
print: | |
needs: [changes, config-changes] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Print | |
run: | | |
echo ${{ github.event_name }} | |
echo ${{ github.event.pull_request.merged == true }} | |
echo ${{(github.event_name == 'pull_request' && github.event.pull_request.merged == true) && (needs.changes.outputs.apps != '[]' || needs.config-changes.outputs.changes != '[]') }} | |
build: | |
needs: [changes, config-changes, lint, test] | |
if: always() && (needs.lint.result == 'success' || needs.lint.result == 'skipped') && (needs.test.result == 'success' || needs.test.result == 'skipped') && (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 | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Azure Login | |
uses: azure/login@v1 | |
id: login | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@1 | |
with: | |
terraform_version: 1.6.6 | |
- name: Terraform Init | |
run: terraform init | |
- name: Terraform Apply | |
run: | | |
terraform apply -auto-approve \ | |
-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 advertisement-service-secrets \ | |
--from-literal=DATABASE_CONNECTION_STRING="$(terraform output advertisements_db_connection_string)" | |
kubectl create secret generic account-service-secrets \ | |
--from-literal=DATABASE_CONNECTION_STRING="$(terraform output accounts_db_connection_string)" | |
- 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 }} |