mirror of
https://github.com/SpecterOps/Nemesis
synced 2026-06-08 12:36:42 +00:00
b59e5979d9
- Update GitHub build workflows
215 lines
7.4 KiB
YAML
215 lines
7.4 KiB
YAML
name: Build and Publish Service Docker Images
|
|
|
|
on:
|
|
push:
|
|
# # To run on every push to main
|
|
# branches: [ "main" ]
|
|
|
|
# To run when release tags are created:
|
|
tags: [ "v*.*.*" ]
|
|
workflow_dispatch: # For manual triggering
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_PREFIX: "specterops/nemesis" # ${{ github.repository }} causes issues as SpecterOps is not all lowercase
|
|
|
|
jobs:
|
|
|
|
build-service-images:
|
|
runs-on: ${{ matrix.runner }}
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
strategy:
|
|
matrix:
|
|
runner: [ubuntu-22.04, ubuntu-22.04-arm]
|
|
service:
|
|
- name: agents
|
|
context: .
|
|
dockerfile: ./projects/agents/Dockerfile
|
|
- name: alerting
|
|
context: .
|
|
dockerfile: ./projects/alerting/Dockerfile
|
|
- name: cli
|
|
context: .
|
|
dockerfile: ./projects/cli/Dockerfile
|
|
- name: document-conversion
|
|
context: .
|
|
dockerfile: ./projects/document_conversion/Dockerfile
|
|
- name: dotnet-service
|
|
context: .
|
|
dockerfile: ./projects/dotnet_service/Dockerfile
|
|
- name: file-enrichment
|
|
context: .
|
|
dockerfile: ./projects/file_enrichment/Dockerfile
|
|
- name: frontend
|
|
context: ./projects/frontend
|
|
dockerfile: ./projects/frontend/Dockerfile
|
|
- name: housekeeping
|
|
context: .
|
|
dockerfile: ./projects/housekeeping/Dockerfile
|
|
- name: jupyter
|
|
context: ./projects/jupyter
|
|
dockerfile: ./projects/jupyter/Dockerfile
|
|
- name: web-api
|
|
context: .
|
|
dockerfile: ./projects/web_api/Dockerfile
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # Fetch all history for git info
|
|
|
|
- name: Generate version.json
|
|
run: |
|
|
cat > version.json << EOF
|
|
{
|
|
"git": {
|
|
"sha": "${{ github.sha }}",
|
|
"shaShort": "$(echo ${{ github.sha }} | cut -c1-7)",
|
|
"branch": "${{ github.ref_name }}",
|
|
"tag": "${{ github.ref_type == 'tag' && github.ref_name || '' }}",
|
|
"dirty": false,
|
|
"commitTimestamp": "$(git log -1 --format=%cI)",
|
|
"commitMessage": "$(git log -1 --pretty=%B | head -n 1)",
|
|
"commitAuthor": "$(git log -1 --pretty=format:'%an')"
|
|
},
|
|
"build": {
|
|
"timestamp": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
|
|
"source": "GitHub Actions"
|
|
}
|
|
}
|
|
EOF
|
|
echo "Generated version.json:"
|
|
cat version.json
|
|
# Copy to frontend public directory for frontend service
|
|
if [ "${{ matrix.service.name }}" = "frontend" ]; then
|
|
cp version.json ./projects/frontend/public/version.json
|
|
echo "Copied version.json to frontend public directory"
|
|
fi
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to the Container registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set platform variables
|
|
run: |
|
|
if [ "${{ matrix.runner }}" = "ubuntu-22.04" ]; then
|
|
echo "PLATFORM=linux/amd64" >> $GITHUB_ENV
|
|
echo "ARCH=amd64" >> $GITHUB_ENV
|
|
else
|
|
echo "PLATFORM=linux/arm64" >> $GITHUB_ENV
|
|
echo "ARCH=arm64" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Extract metadata for ${{ matrix.service.name }} image
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ matrix.service.name }}
|
|
tags: |
|
|
type=sha,format=short,suffix=-${{ env.ARCH }}
|
|
type=ref,event=branch,suffix=-${{ env.ARCH }}
|
|
type=ref,event=pr,suffix=-${{ env.ARCH }}
|
|
type=raw,value=latest-${{ env.ARCH }},enable={{is_default_branch}}
|
|
type=raw,value=${{ github.ref_name }}-${{ env.ARCH }}
|
|
|
|
- name: Build and push ${{ matrix.service.name }} image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ${{ matrix.service.context }}
|
|
file: ${{ matrix.service.dockerfile }}
|
|
push: true
|
|
platforms: ${{ env.PLATFORM }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
build-args: |
|
|
PYTHON_BASE_DEV_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/python-base-dev:latest
|
|
PYTHON_BASE_PROD_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/python-base-prod:latest
|
|
INSPECT_ASSEMBLY_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/inspect-assembly:latest
|
|
cache-from: |
|
|
type=gha,scope=${{ matrix.service.name }}-${{ env.ARCH }}-${{ github.ref_name }}
|
|
type=gha,scope=${{ matrix.service.name }}-${{ env.ARCH }}-main
|
|
cache-to: |
|
|
type=gha,mode=max,scope=${{ matrix.service.name }}-${{ env.ARCH }}-${{ github.ref_name }}
|
|
|
|
# Create multi-arch manifest
|
|
create-manifest:
|
|
needs: build-service-images
|
|
runs-on: ubuntu-22.04
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
strategy:
|
|
matrix:
|
|
service:
|
|
- web-api
|
|
- dotnet-api
|
|
- file-enrichment
|
|
- frontend
|
|
- jupyter
|
|
- alerting
|
|
- triage
|
|
- cli
|
|
- housekeeping
|
|
- document-conversion
|
|
|
|
steps:
|
|
- name: Log in to the Container registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata for manifest
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ matrix.service }}
|
|
tags: |
|
|
type=sha,format=short
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
type=raw,value=${{ github.ref_name }}
|
|
|
|
- name: Create and push multi-arch manifest
|
|
run: |
|
|
# Create multi-arch manifests for each tag
|
|
echo '${{ steps.meta.outputs.tags }}' | while IFS= read -r tag; do
|
|
if [ -n "$tag" ]; then
|
|
echo "Creating manifest for: $tag"
|
|
|
|
# Check which images actually exist
|
|
IMAGES=""
|
|
if docker buildx imagetools inspect "${tag}-amd64" > /dev/null 2>&1; then
|
|
IMAGES="$IMAGES ${tag}-amd64"
|
|
echo "Found AMD64 image: ${tag}-amd64"
|
|
else
|
|
echo "WARNING: AMD64 image not found: ${tag}-amd64"
|
|
fi
|
|
|
|
if docker buildx imagetools inspect "${tag}-arm64" > /dev/null 2>&1; then
|
|
IMAGES="$IMAGES ${tag}-arm64"
|
|
echo "Found ARM64 image: ${tag}-arm64"
|
|
else
|
|
echo "WARNING: ARM64 image not found: ${tag}-arm64"
|
|
fi
|
|
|
|
if [ -n "$IMAGES" ]; then
|
|
echo "Creating manifest with images:$IMAGES"
|
|
docker buildx imagetools create --tag "$tag" $IMAGES
|
|
else
|
|
echo "ERROR: No images found for $tag"
|
|
exit 1
|
|
fi
|
|
fi
|
|
done |