Skip to content

Build and deploy frontend #6

Build and deploy frontend

Build and deploy frontend #6

name: Build and deploy frontend
on:
workflow_dispatch:
push:
branches: [ "deployment-automation" ]
paths:
- 'frontend/**'
jobs:
build:
runs-on: ubuntu-latest
env:
imageRepository: 'frontend'
containerRegistry: 'psgloboticket.azurecr.io'
dockerfilePath: 'frontend/Dockerfile'
deploymentFile: 'frontend.yaml'
namespace: 'globoticket'
steps:
- uses: actions/checkout@v3
- name: Login to DockerHub
uses: docker/login-action@v2
with:
registry: ${{ env.containerRegistry }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_TOKEN }}
- name: Build an image from Dockerfile
run: |
docker build -t ${{env.containerRegistry}}/${{env.imageRepository}}:${{github.run_number}} -f ${{env.dockerfilePath}} ${{github.workspace}}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: '${{env.containerRegistry}}/${{env.imageRepository}}:${{github.run_number}}'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
- name: push image to ACR
run: |
docker push ${{env.containerRegistry}}/${{env.imageRepository}}:${{github.run_number}}
- name: Replace tokens
uses: cschleiden/[email protected]
with:
files: ${{github.workspace}}/demos/remote-k8s/deployment-automation/${{env.deploymentFile}}
env:
Build.BuildId: ${{github.run_number}}
- name: Upload a Build Artifact
uses: actions/[email protected]
with:
name: deployfile
path: ${{github.workspace}}/demos/remote-k8s/deployment-automation/${{env.deploymentFile}}
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: deployfile
- uses: azure/k8s-set-context@v1
with:
method: kubeconfig
kubeconfig: ${{secrets.KUBECONFIG}}
id: setcontext
- uses: Azure/k8s-deploy@v4
with:
namespace: 'globoticket'
manifests: |
./${{env.deploymentFile}}