Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2856b170ad | |||
| f5556870b2 | |||
| c56ae1b9d3 | |||
|
|
9af823b096 | ||
| 412dce2349 | |||
| 4f0695474d | |||
| 8b880261b8 | |||
| 22970d11f3 | |||
| b88cba1a44 | |||
| 98e7c3f6b9 | |||
| fe581e0c83 | |||
| d6c7bb8956 | |||
| bb39fb5f9e | |||
| 4510f6ff7f | |||
| 48bccb4afa |
37
.gitea/actions/compose-up/action.yml
Normal file
37
.gitea/actions/compose-up/action.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
name: compose-up
|
||||||
|
description: Run docker compose up using an explicit image (DOCKER_IMAGE) on Linux/Windows.
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
image:
|
||||||
|
description: Full image reference (registry/repo:tag or @sha256:...)
|
||||||
|
required: true
|
||||||
|
workdir:
|
||||||
|
description: Directory containing compose files on the runner
|
||||||
|
required: false
|
||||||
|
default: .
|
||||||
|
compose_args:
|
||||||
|
description: Arguments after `docker compose` (default runs up -d with pull)
|
||||||
|
required: false
|
||||||
|
default: up -d --pull always --remove-orphans
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
- name: Compose Up (Linux/macOS)
|
||||||
|
if: runner.os != 'Windows'
|
||||||
|
shell: bash
|
||||||
|
working-directory: ${{ inputs.workdir }}
|
||||||
|
env:
|
||||||
|
DOCKER_IMAGE: ${{ inputs.image }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
docker compose ${{ inputs.compose_args }}
|
||||||
|
|
||||||
|
- name: Compose Up (Windows)
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
shell: pwsh
|
||||||
|
working-directory: ${{ inputs.workdir }}
|
||||||
|
env:
|
||||||
|
DOCKER_IMAGE: ${{ inputs.image }}
|
||||||
|
run: |
|
||||||
|
docker compose ${{ inputs.compose_args }}
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
name: Deploy Template
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_call:
|
|
||||||
inputs:
|
|
||||||
runner:
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
image:
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
runs-on: ${{ inputs.runner }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Show target server
|
|
||||||
run: echo "Deploying on ${{ inputs.runner }}"
|
|
||||||
|
|
||||||
# Force compose to use the exact image tag we built/pushed, regardless of
|
|
||||||
# what the server's compose file has hard-coded.
|
|
||||||
- name: Compose Up (Linux)
|
|
||||||
if: runner.os != 'Windows'
|
|
||||||
env:
|
|
||||||
DOCKER_IMAGE: ${{ inputs.image }}
|
|
||||||
run: |
|
|
||||||
docker compose up -d --pull always --remove-orphans
|
|
||||||
|
|
||||||
- name: Compose Up (Windows)
|
|
||||||
if: runner.os == 'Windows'
|
|
||||||
env:
|
|
||||||
DOCKER_IMAGE: ${{ inputs.image }}
|
|
||||||
run: |
|
|
||||||
docker compose up -d --pull always --remove-orphans
|
|
||||||
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
name: Docker Build & Push (Template)
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_call:
|
|
||||||
inputs:
|
|
||||||
runner:
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
default: ubuntu-latest
|
|
||||||
image_name:
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
image_tag:
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
default: latest
|
|
||||||
dockerfile:
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
default: Dockerfile
|
|
||||||
context:
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
default: .
|
|
||||||
outputs:
|
|
||||||
image:
|
|
||||||
description: Fully-qualified image reference pushed to Docker Hub
|
|
||||||
value: ${{ jobs.build.outputs.image }}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ${{ inputs.runner }}
|
|
||||||
outputs:
|
|
||||||
image: ${{ steps.push.outputs.image }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Build Docker image
|
|
||||||
run: |
|
|
||||||
docker build \
|
|
||||||
-t "${{ inputs.image_name }}:${{ inputs.image_tag }}" \
|
|
||||||
-f "${{ inputs.dockerfile }}" \
|
|
||||||
"${{ inputs.context }}"
|
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
username: ${{ env.DOCKER_HUB_USERNAME }}
|
|
||||||
password: ${{ env.DOCKER_HUB_ACCESS_TOKEN }}
|
|
||||||
|
|
||||||
- name: Push Docker image to Docker Hub
|
|
||||||
id: push
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
REMOTE_IMAGE="${{ env.DOCKER_HUB_USERNAME }}/${{ inputs.image_name }}:${{ inputs.image_tag }}"
|
|
||||||
docker tag "${{ inputs.image_name }}:${{ inputs.image_tag }}" "$REMOTE_IMAGE"
|
|
||||||
docker push "$REMOTE_IMAGE"
|
|
||||||
echo "image=$REMOTE_IMAGE" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
148
.gitea/workflows/harbor-build-deploy.yml
Normal file
148
.gitea/workflows/harbor-build-deploy.yml
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
name: Harbor Build Once → Deploy Many (Compose)
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
harbor_registry:
|
||||||
|
type: string
|
||||||
|
default: harbor.hcmc.online
|
||||||
|
harbor_project:
|
||||||
|
type: string
|
||||||
|
default: ci
|
||||||
|
image_repo:
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
|
||||||
|
context:
|
||||||
|
type: string
|
||||||
|
default: .
|
||||||
|
dockerfile:
|
||||||
|
type: string
|
||||||
|
default: Dockerfile
|
||||||
|
platforms:
|
||||||
|
type: string
|
||||||
|
default: linux/amd64,linux/arm64
|
||||||
|
|
||||||
|
# IMPORTANT CHANGE
|
||||||
|
deploy_runners_json:
|
||||||
|
description: 'JSON array of runner labels'
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
|
||||||
|
compose_workdir:
|
||||||
|
type: string
|
||||||
|
default: .
|
||||||
|
compose_args:
|
||||||
|
type: string
|
||||||
|
default: up -d --pull always --remove-orphans
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
HARBOR_PUSH_USERNAME: { required: true }
|
||||||
|
HARBOR_PUSH_PASSWORD: { required: true }
|
||||||
|
HARBOR_PULL_USERNAME: { required: true }
|
||||||
|
HARBOR_PULL_PASSWORD: { required: true }
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# BUILD ONCE (single powerful runner)
|
||||||
|
# ==========================================================
|
||||||
|
build_and_push:
|
||||||
|
name: Build & Push Image
|
||||||
|
runs-on: devsg-atlantic
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
image_repo: ${{ steps.meta.outputs.image_repo }}
|
||||||
|
image_digest: ${{ steps.build.outputs.digest }}
|
||||||
|
image_ref: ${{ steps.meta.outputs.image_repo }}@${{ steps.build.outputs.digest }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Compute image metadata
|
||||||
|
id: meta
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
IMAGE="${{ inputs.harbor_registry }}/${{ inputs.harbor_project }}/${{ inputs.image_repo }}"
|
||||||
|
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-12)
|
||||||
|
BRANCH="${{ github.ref_name }}"
|
||||||
|
|
||||||
|
echo "image_repo=$IMAGE" >> $GITHUB_OUTPUT
|
||||||
|
echo "sha_tag=sha-$SHORT_SHA" >> $GITHUB_OUTPUT
|
||||||
|
echo "branch_tag=$BRANCH" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Login Harbor (push)
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ inputs.harbor_registry }}
|
||||||
|
username: ${{ secrets.HARBOR_PUSH_USERNAME }}
|
||||||
|
password: ${{ secrets.HARBOR_PUSH_PASSWORD }}
|
||||||
|
|
||||||
|
# Cached multi-platform build
|
||||||
|
- name: Build & Push Image
|
||||||
|
id: build
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: ${{ inputs.context }}
|
||||||
|
file: ${{ inputs.dockerfile }}
|
||||||
|
platforms: ${{ inputs.platforms }}
|
||||||
|
push: true
|
||||||
|
|
||||||
|
tags: |
|
||||||
|
${{ steps.meta.outputs.image_repo }}:${{ steps.meta.outputs.sha_tag }}
|
||||||
|
${{ steps.meta.outputs.image_repo }}:${{ steps.meta.outputs.branch_tag }}
|
||||||
|
${{ steps.meta.outputs.image_repo }}:latest
|
||||||
|
|
||||||
|
cache-from: type=registry,ref=${{ steps.meta.outputs.image_repo }}:buildcache
|
||||||
|
cache-to: type=registry,ref=${{ steps.meta.outputs.image_repo }}:buildcache,mode=max
|
||||||
|
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# DEPLOY MANY (fan-out runners)
|
||||||
|
# ==========================================================
|
||||||
|
deploy:
|
||||||
|
name: Deploy to Fleet
|
||||||
|
needs: build_and_push
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
runner: ${{ fromJSON(inputs.deploy_runners_json) }}
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.runner }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Login Harbor (pull)
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ inputs.harbor_registry }}
|
||||||
|
username: ${{ secrets.HARBOR_PULL_USERNAME }}
|
||||||
|
password: ${{ secrets.HARBOR_PULL_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Show image
|
||||||
|
run: echo "Deploying ${{ needs.build_and_push.outputs.image_ref }}"
|
||||||
|
|
||||||
|
# Linux/macOS
|
||||||
|
- name: Compose Up (Unix)
|
||||||
|
if: runner.os != 'Windows'
|
||||||
|
shell: bash
|
||||||
|
working-directory: ${{ inputs.compose_workdir }}
|
||||||
|
env:
|
||||||
|
DOCKER_IMAGE: ${{ needs.build_and_push.outputs.image_ref }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
docker compose ${{ inputs.compose_args }}
|
||||||
|
|
||||||
|
# Windows runners support
|
||||||
|
- name: Compose Up (Windows)
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
shell: pwsh
|
||||||
|
working-directory: ${{ inputs.compose_workdir }}
|
||||||
|
env:
|
||||||
|
DOCKER_IMAGE: ${{ needs.build_and_push.outputs.image_ref }}
|
||||||
|
run: |
|
||||||
|
docker compose ${{ inputs.compose_args }}
|
||||||
Reference in New Issue
Block a user