feat: add CI/CD workflow automation
All checks were successful
Build and Push to ACR / Build and Push (push) Successful in 3m58s
All checks were successful
Build and Push to ACR / Build and Push (push) Successful in 3m58s
This commit is contained in:
79
.gitea/workflows/build-push.yml
Normal file
79
.gitea/workflows/build-push.yml
Normal file
@@ -0,0 +1,79 @@
|
||||
name: Build and Push to ACR
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
workflow_dispatch: {}
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
AZURE_FEDERATED_TOKEN_FILE: /var/run/secrets/azure/tokens/azure-identity-token
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build and Push
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Node.js 20
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
# cache: 'npm' omitted — requires package-lock.json which may not exist yet
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
- name: Build project
|
||||
run: npm run build || echo "No build script configured"
|
||||
- name: Run tests
|
||||
run: npm test || echo "No tests configured"
|
||||
|
||||
- name: Security Scan - Trivy
|
||||
continue-on-error: true
|
||||
run: |
|
||||
# Download release tarball directly — avoids install.sh which calls
|
||||
# api.github.com/releases/tags/... and fails in network-restricted runners.
|
||||
TRIVY_VERSION="0.57.1"
|
||||
TRIVY_BIN="/tmp/trivy-bin/trivy"
|
||||
if ! command -v trivy &>/dev/null; then
|
||||
mkdir -p /tmp/trivy-bin
|
||||
curl -sfLo /tmp/trivy.tar.gz "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz"
|
||||
tar -xzf /tmp/trivy.tar.gz -C /tmp/trivy-bin trivy
|
||||
chmod +x "${TRIVY_BIN}"
|
||||
else
|
||||
TRIVY_BIN="$(command -v trivy)"
|
||||
fi
|
||||
# Filesystem scan — exit-code 0 so findings are reported but never block the build
|
||||
"${TRIVY_BIN}" fs --severity HIGH,CRITICAL --exit-code 0 --format table --skip-db-update --offline-scan . || "${TRIVY_BIN}" fs --severity HIGH,CRITICAL --exit-code 0 --format table .
|
||||
|
||||
- name: Install Azure CLI
|
||||
run: |
|
||||
if ! command -v az &>/dev/null; then
|
||||
curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
||||
fi
|
||||
- name: Azure login (OIDC)
|
||||
run: |
|
||||
az login \
|
||||
--service-principal \
|
||||
--username "$AZURE_CLIENT_ID" \
|
||||
--tenant "$AZURE_TENANT_ID" \
|
||||
--federated-token "$(cat $AZURE_FEDERATED_TOKEN_FILE)"
|
||||
- name: Build and push via ACR Tasks
|
||||
run: |
|
||||
SHORT_SHA=$(echo "${{ gitea.sha }}" | cut -c1-7)
|
||||
az acr build \
|
||||
--registry bstagecjotdevacr \
|
||||
--image mohamed-node-mod-1:$SHORT_SHA \
|
||||
--image mohamed-node-mod-1:latest \
|
||||
--file Dockerfile \
|
||||
.
|
||||
echo "✓ Pushed: bstagecjotdevacr.azurecr.io/mohamed-node-mod-1:$SHORT_SHA"
|
||||
Reference in New Issue
Block a user