Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/02-tests-ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
name: "Nível 2: Testes Automatizados"
on:
pull_request:
branches: [main]
branches:
- main
- feature/desafio03


env:
NODE_VERSION: "18"
CHALLENGE_LEVEL: 2
CHALLENGE_NAME: "testes-automatizados"
COVERAGE_MIN: 99 # Cobertura mínima exigida em porcentagem
COVERAGE_MIN: 80 # Cobertura mínima exigida em porcentagem

jobs:
tests-and-coverage:
Expand All @@ -26,7 +28,7 @@ jobs:
with:
node-version: ${{ env.NODE_VERSION }}

- name: "Instalar Deps"
- name: "Instalar Dependencias"
run: npm ci

- name: "Executar tests"
Expand Down
65 changes: 62 additions & 3 deletions .github/workflows/03-build-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "Nível 3: Containers e Segurança"
on:
pull_request:
types: [closed]
branches: [ desafio-nivel-3 ]
branches: [feature/desafio03]

permissions:
contents: read
Expand All @@ -12,17 +12,76 @@ permissions:
env:
CHALLENGE_LEVEL: 3
CHALLENGE_NAME: "containers-e-seguranca"
REGISTRY: ghcr.io
REGISTRY: ghcr.iodesafio-nivel-3

jobs:
build-scan-and-push:
name: "Build, Lint, Trivy Scan e Push no GHCR"
if: #????
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
# AQUI VAI O CÓDIGO DO DESAFIO :)

- name: Checkout repository
uses: actions/checkout@v3

- name: Lint Dockerfile with Hadolint
uses: hadolint/hadolint-action@v2
with:
dockerfile: Dockerfile
format: tty
output-file: lint-report.txt
no-fail: true

- name: Check for DL3006 or DL3008 violations
run: |
if grep -qE "DL3006|DL3008" lint-report.txt; then
echo "Linting failed due to DL3006 or DL3008." && exit 1;
fi
- name: Upload lint report
uses: actions/upload-artifact@v3
with:
name: lint-report
path: lint-report.txt

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image
id: build-image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: false
tags: ghcr.io/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ github.sha }}

- name: Scan Docker image for vulnerabilities with Trivy
id: scan-image
uses: aquasecurity/trivy-action@0.28.0
with:
image-ref: ghcr.io/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ github.sha }}
format: table
output: trivy-report.txt

- name: Check for critical vulnerabilities
run: |
if grep -q "CRITICAL" trivy-report.txt; then
echo "Critical vulnerabilities found." && exit 1;
fi
shell: bash

- name: Upload Trivy report
uses: actions/upload-artifact@v4
with:
name: trivy-report
path: trivy-report.txt

generate-certificate: # DAQUI PARA BAIXO, NÃO ALTERAR
name: "Desafio Nível 3 - Certificado"
needs: build-scan-and-push
Expand Down