This commit is contained in:
@@ -4,7 +4,7 @@ on:
|
|||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
image_name:
|
image_name:
|
||||||
description: Fully qualified image repository without a tag
|
description: Fully qualified Gitea Registry image repository without a tag
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
dockerfile:
|
dockerfile:
|
||||||
@@ -16,22 +16,17 @@ on:
|
|||||||
default: .
|
default: .
|
||||||
type: string
|
type: string
|
||||||
test_command:
|
test_command:
|
||||||
description: Source-level test command supplied by the calling repository
|
description: Optional source-level test command
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
type: string
|
type: string
|
||||||
image_test_command:
|
deploy_service:
|
||||||
description: Optional command executed inside the built image
|
description: Dev service to candidate-test and promote
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
type: string
|
type: string
|
||||||
candidate_command:
|
deploy_host:
|
||||||
description: Optional Dev candidate-stack command executed after image push
|
description: Restricted Dev deployment host
|
||||||
required: false
|
|
||||||
default: ""
|
|
||||||
type: string
|
|
||||||
promote_command:
|
|
||||||
description: Optional atomic Dev promotion command executed only for v* tags
|
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
type: string
|
type: string
|
||||||
@@ -46,21 +41,19 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test-build-publish:
|
test-build-publish:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
outputs:
|
|
||||||
image_tag: ${{ steps.meta.outputs.image_tag }}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: https://gitea.waternetwork.cn/actions/checkout@v4
|
||||||
- id: meta
|
with:
|
||||||
run: echo "image_tag=sha-${GITEA_SHA}" >> "$GITHUB_OUTPUT"
|
fetch-depth: 1
|
||||||
- name: Source tests
|
- name: Source tests
|
||||||
if: ${{ inputs.test_command != '' }}
|
if: ${{ inputs.test_command != '' }}
|
||||||
run: ${{ inputs.test_command }}
|
run: ${{ inputs.test_command }}
|
||||||
- name: Build immutable candidate image
|
- name: Build immutable candidate image
|
||||||
run: docker build --pull=false -f "${{ inputs.dockerfile }}" -t "${{ inputs.image_name }}:sha-${GITEA_SHA}" "${{ inputs.build_context }}"
|
run: |
|
||||||
- name: Image tests
|
set -eu
|
||||||
if: ${{ inputs.image_test_command != '' }}
|
docker build --pull=false -f "${{ inputs.dockerfile }}" \
|
||||||
run: docker run --rm "${{ inputs.image_name }}:sha-${GITEA_SHA}" sh -lc '${{ inputs.image_test_command }}'
|
-t "${{ inputs.image_name }}:sha-${GITEA_SHA}" "${{ inputs.build_context }}"
|
||||||
- name: Publish candidate image
|
- name: Login and publish candidate image
|
||||||
env:
|
env:
|
||||||
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
@@ -69,16 +62,24 @@ jobs:
|
|||||||
registry="$(printf '%s' '${{ inputs.image_name }}' | cut -d/ -f1)"
|
registry="$(printf '%s' '${{ inputs.image_name }}' | cut -d/ -f1)"
|
||||||
printf '%s' "$REGISTRY_PASSWORD" | docker login "$registry" -u "$REGISTRY_USERNAME" --password-stdin
|
printf '%s' "$REGISTRY_PASSWORD" | docker login "$registry" -u "$REGISTRY_USERNAME" --password-stdin
|
||||||
docker push "${{ inputs.image_name }}:sha-${GITEA_SHA}"
|
docker push "${{ inputs.image_name }}:sha-${GITEA_SHA}"
|
||||||
- name: Candidate test on Dev
|
- name: Candidate pull on Dev
|
||||||
if: ${{ inputs.candidate_command != '' && secrets.DEV_DEPLOY_SSH_KEY != '' }}
|
if: ${{ inputs.deploy_service != '' && inputs.deploy_host != '' }}
|
||||||
env:
|
env:
|
||||||
DEV_DEPLOY_SSH_KEY: ${{ secrets.DEV_DEPLOY_SSH_KEY }}
|
DEV_DEPLOY_SSH_KEY: ${{ secrets.DEV_DEPLOY_SSH_KEY }}
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
install -m 700 -d ~/.ssh
|
test -n "$DEV_DEPLOY_SSH_KEY"
|
||||||
|
install -d -m 700 ~/.ssh
|
||||||
printf '%s\n' "$DEV_DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
|
printf '%s\n' "$DEV_DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
|
||||||
chmod 600 ~/.ssh/id_ed25519
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
${{ inputs.candidate_command }} "${{ inputs.image_name }}:sha-${GITEA_SHA}"
|
ssh-keyscan -H "${{ inputs.deploy_host }}" >> ~/.ssh/known_hosts
|
||||||
- name: Promote release after candidate health check
|
ssh -i ~/.ssh/id_ed25519 cicd-deploy@"${{ inputs.deploy_host }}" \
|
||||||
if: ${{ startsWith(gitea.ref, 'refs/tags/v') && inputs.promote_command != '' && secrets.DEV_DEPLOY_SSH_KEY != '' }}
|
"candidate ${{ inputs.deploy_service }} ${{ inputs.image_name }}:sha-${GITEA_SHA}"
|
||||||
run: ${{ inputs.promote_command }} "${{ inputs.image_name }}:sha-${GITEA_SHA}"
|
- name: Promote tagged release after candidate check
|
||||||
|
if: ${{ startsWith(gitea.ref, 'refs/tags/v') && inputs.deploy_service != '' && inputs.deploy_host != '' }}
|
||||||
|
env:
|
||||||
|
DEV_DEPLOY_SSH_KEY: ${{ secrets.DEV_DEPLOY_SSH_KEY }}
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
ssh -i ~/.ssh/id_ed25519 cicd-deploy@"${{ inputs.deploy_host }}" \
|
||||||
|
"promote ${{ inputs.deploy_service }} ${{ inputs.image_name }}:sha-${GITEA_SHA}"
|
||||||
|
|||||||
Reference in New Issue
Block a user