- Non-prod workflow: builds on push to main, pushes to acme-nonprod registry, creates Octopus release in Non-Prod channel - Prod workflow: builds on v* tags, pushes to acme-prod registry, creates Octopus release in Prod channel - Simple Alpine Dockerfile for demo purposes
63 lines
2.0 KiB
YAML
63 lines
2.0 KiB
YAML
name: Build Prod Image
|
|
|
|
on:
|
|
push:
|
|
tags: ['v*']
|
|
|
|
env:
|
|
REGISTRY: gitea.oreillyit.nz
|
|
IMAGE: acme-prod/demo-app
|
|
OCTOPUS_SERVER: https://taniwha.octopus.app
|
|
OCTOPUS_SPACE_ID: Spaces-102
|
|
OCTOPUS_PROJECT_ID: Projects-101
|
|
OCTOPUS_CHANNEL_ID: Channels-125
|
|
|
|
jobs:
|
|
build-and-release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Generate version
|
|
id: version
|
|
run: echo "sha=sha-${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Login to registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Build and push
|
|
run: |
|
|
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ steps.version.outputs.sha }} .
|
|
docker push ${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ steps.version.outputs.sha }}
|
|
|
|
- name: Create Octopus Release
|
|
run: |
|
|
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
|
|
-H "X-Octopus-ApiKey: ${{ secrets.OCTOPUS_API_KEY }}" \
|
|
-H "Content-Type: application/json" \
|
|
"${{ env.OCTOPUS_SERVER }}/api/${{ env.OCTOPUS_SPACE_ID }}/releases" \
|
|
-d '{
|
|
"ProjectId": "${{ env.OCTOPUS_PROJECT_ID }}",
|
|
"ChannelId": "${{ env.OCTOPUS_CHANNEL_ID }}",
|
|
"Version": "prod-${{ steps.version.outputs.sha }}",
|
|
"SelectedPackages": [
|
|
{
|
|
"ActionName": "Deploy Prod Image",
|
|
"PackageReferenceName": "demo-app",
|
|
"Version": "${{ steps.version.outputs.sha }}"
|
|
}
|
|
]
|
|
}')
|
|
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
|
|
BODY=$(echo "$RESPONSE" | sed '$d')
|
|
echo "Response: $BODY"
|
|
if [ "$HTTP_CODE" -ge 400 ]; then
|
|
echo "::error::Failed to create release (HTTP $HTTP_CODE)"
|
|
exit 1
|
|
fi
|
|
echo "Release created successfully"
|