Running the project on my raspberry pi #26
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 Pipeline | |
on: | |
push: | |
branches: | |
- main | |
- main-week2-day5-6 | |
pull_request: | |
branches: | |
- main | |
permissions: | |
contents: read | |
packages: write | |
security-events: write | |
env: | |
DOCKER_IMAGE_NAME: devsecops-ts-cdk-security | |
DOCKER_IMAGE_TAG: ${{ github.sha }} | |
jobs: | |
build: | |
runs-on: [self-hosted, nodejs-build] # Added label for this project | |
environment: dev | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20' | |
- name: Install dependencies | |
run: npm install | |
- name: Build project | |
run: npm run build | |
- name: Run tests | |
run: npm test | |
- name: CDK Synth | |
run: npm run cdk-synth | |
env: | |
CDK_DEFAULT_ACCOUNT: ${{ vars.AWS_ACCOUNT_ID }} | |
CDK_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }} | |
checkov: | |
runs-on: [self-hosted, nodejs-build] # Added label for this project | |
needs: build | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.8' | |
- name: Install Checkov | |
run: pip install checkov | |
- name: Run Checkov | |
run: checkov -d . | |
docker: | |
runs-on: [self-hosted, nodejs-build] # Added label for this project | |
needs: checkov | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- 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 | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
load: true | |
tags: | | |
${{ env.DOCKER_IMAGE_NAME }}:latest | |
${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG }} | |
ghcr.io/${{ github.repository }}/${{ env.DOCKER_IMAGE_NAME }}:latest | |
ghcr.io/${{ github.repository }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/trivy-action@master | |
with: | |
image-ref: ${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG }} | |
format: 'sarif' | |
output: 'trivy-results.sarif' | |
severity: 'CRITICAL,HIGH' | |
- name: Upload Trivy scan results to GitHub Security tab | |
uses: github/codeql-action/upload-sarif@v3 | |
with: | |
sarif_file: 'trivy-results.sarif' | |
- name: Push Docker image | |
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/main-week2-day5-6') | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: | | |
ghcr.io/${{ github.repository }}/${{ env.DOCKER_IMAGE_NAME }}:latest | |
ghcr.io/${{ github.repository }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |