test: teste de deploy #6
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: pipeline | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: | | |
"${{ vars.REGISTRY }}/${{ vars.IMAGE }}:${{ github.sha}}" | |
"${{ vars.REGISTRY }}/${{ vars.IMAGE }}:latest" | |
scan-vuln-with-trivy: | |
runs-on: ubuntu-latest | |
needs: [build-and-push] | |
steps: | |
- name: Scan vulnerabilities with Trivy | |
uses: aquasecurity/trivy-action@master | |
with: | |
image-ref: '${{ vars.REGISTRY }}/${{ vars.IMAGE }}:${{ github.sha }}' | |
vuln-type: 'os,library' | |
severity: 'CRITICAL,HIGH' | |
ignore-unfixed: true | |
template: '@/contrib/html.tpl' | |
exit-code: '0' | |
format: 'template' | |
output: report.html | |
env: | |
TRIVY_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
TRIVY_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Upload Trivy Report | |
uses: actions/upload-artifact@v2 | |
with: | |
name: trivy-report | |
path: report.html | |
deploy-on-k8s: | |
runs-on: 'ubuntu-latest' | |
needs: [build-and-push, scan-vuln-with-trivy] | |
steps: | |
- name: Checkout this repo | |
uses: actions/checkout@v4 | |
with: | |
path: main | |
- name: Checkout repo helm | |
uses: actions/checkout@v4 | |
with: | |
repository: 'gutobrutus/helm-adventures' | |
sparse-checkout: charts/hello-django | |
path: helm | |
# Sobe um cluster com kind apenas para teste de pipeline | |
# Comentar se não for para teste | |
- name: Create k8s Kind Cluster | |
uses: helm/[email protected] | |
- name: Deploy com helm | |
run: | | |
kubectl get nodes | |
helm upgrade --install --atomic --timeout 1m hello-django \ | |
helm/charts/hello-django \ | |
--namespace pipeline --create-namespace \ | |
--set settingsPy.secretKey=${{ secrets.SECRET_KEY_DJANGO }} \ | |
--set settingsPy.debug=False \ | |
--set settingsPy.databaseUser=${{ secrets.DB_USER }} \ | |
--set settingsPy.databasePassword=${{ secrets.DB_PASS }} \ | |
--set settingsPy.databaseHost=${{ vars.DB_HOST }} \ | |
--set settingsPy.databasePort=${{ vars.DB_PORT }} \ | |
--set image.tag=${{ github.sha }} --dry-run |