improvement: workflow updated for git actions.

This commit is contained in:
2026-05-05 00:33:30 +03:30
parent d03ecdfc7c
commit 517ce0d5ba
2 changed files with 95 additions and 73 deletions

View File

@@ -12,13 +12,14 @@
# Optional: # Optional:
# STAGING_HTTP_PORT host port for nginx (default 8088) # STAGING_HTTP_PORT host port for nginx (default 8088)
# #
# Required for deploy job (absolute path on the runner host — forward slashes ok on Windows): # Required for deploy job (absolute path on the runner host):
# DEPLOY_SECRETS_DIR folder containing database.staging.env + backend.staging.env # DEPLOY_SECRETS_DIR folder containing database.staging.env + backend.staging.env
# #
# Runner: self-hosted with Docker; Git Bash recommended on Windows (shell: bash). # Runner: self-hosted with Docker. Default shell is powershell (Windows act_runner often has no WSL bash).
# For a Linux runner, change defaults.run.shell to bash and restore bash syntax if needed.
# #
# We do NOT use gitea.com/actions/checkout — many restricted networks cannot reach gitea.com. # We do NOT use gitea.com/actions/checkout — many restricted networks cannot reach gitea.com.
# Checkout is a plain `git clone` from the same Gitea host (github.server_url / gitea alias). # Checkout is a plain git clone from the same Gitea host.
name: Registry — build, push, deploy name: Registry — build, push, deploy
@@ -29,7 +30,7 @@ on:
defaults: defaults:
run: run:
shell: bash shell: powershell
jobs: jobs:
build-and-push: build-and-push:
@@ -39,57 +40,66 @@ jobs:
steps: steps:
- name: Checkout (clone from this Gitea — no gitea.com) - name: Checkout (clone from this Gitea — no gitea.com)
run: | run: |
set -e $ErrorActionPreference = 'Stop'
SERVER="${{ github.server_url }}" $Server = "${{ github.server_url }}".TrimEnd('/')
SERVER="${SERVER%/}" $Repo = "${{ github.repository }}"
REPO="${{ github.repository }}" $Branch = "${{ github.ref_name }}"
BRANCH="${{ github.ref_name }}" $Token = "${{ github.token }}"
TOKEN="${{ github.token }}" $Actor = "${{ github.actor }}"
ACTOR="${{ github.actor }}" $hp = $Server -replace '^https?://', ''
HP="${SERVER#http://}" if ($Server.StartsWith('https')) {
HP="${HP#https://}" $cloneUrl = 'https://' + $Actor + ':' + $Token + '@' + $hp + '/' + $Repo + '.git'
if [[ "$SERVER" == https://* ]]; then } else {
CLONE_URL="https://${ACTOR}:${TOKEN}@${HP}/${REPO}.git" $cloneUrl = 'http://' + $Actor + ':' + $Token + '@' + $hp + '/' + $Repo + '.git'
else }
CLONE_URL="http://${ACTOR}:${TOKEN}@${HP}/${REPO}.git" $env:GIT_TERMINAL_PROMPT = '0'
fi git clone --depth 1 --branch $Branch $cloneUrl .
GIT_TERMINAL_PROMPT=0 git clone --depth 1 --branch "$BRANCH" "$CLONE_URL" .
- name: Image tag and registry prefix - name: Image tag and registry prefix
id: meta id: meta
run: | run: |
echo "image_tag=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" $ErrorActionPreference = 'Stop'
echo "REGISTRY_PREFIX=${{ vars.REGISTRY_HOST }}/${{ vars.REGISTRY_OWNER }}" >> "$GITHUB_ENV" $short = (git rev-parse --short HEAD).Trim()
$utf8 = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::AppendAllText($env:GITHUB_OUTPUT, "image_tag=$short`n", $utf8)
$prefix = "${{ vars.REGISTRY_HOST }}/${{ vars.REGISTRY_OWNER }}"
[System.IO.File]::AppendAllText($env:GITHUB_ENV, "REGISTRY_PREFIX=$prefix`n", $utf8)
- name: Log in to container registry - name: Log in to container registry
run: | run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login "${{ vars.REGISTRY_HOST }}" \ $ErrorActionPreference = 'Stop'
-u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin $pass = @'
${{ secrets.REGISTRY_PASSWORD }}
'@
$pass.Trim() | docker login "${{ vars.REGISTRY_HOST }}" -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
- name: Build and push backend - name: Build and push backend
run: | run: |
TAG="${{ steps.meta.outputs.image_tag }}" $ErrorActionPreference = 'Stop'
docker build \ $tag = "${{ steps.meta.outputs.image_tag }}"
-t "${REGISTRY_PREFIX}/dyolink-backend:${TAG}" \ docker build `
-t "${REGISTRY_PREFIX}/dyolink-backend:latest" \ -t "$env:REGISTRY_PREFIX/dyolink-backend:$tag" `
-t "$env:REGISTRY_PREFIX/dyolink-backend:latest" `
./backend ./backend
docker push "${REGISTRY_PREFIX}/dyolink-backend:${TAG}" docker push "$env:REGISTRY_PREFIX/dyolink-backend:$tag"
docker push "${REGISTRY_PREFIX}/dyolink-backend:latest" docker push "$env:REGISTRY_PREFIX/dyolink-backend:latest"
- name: Build and push frontend - name: Build and push frontend
env: env:
PUBLIC_BASE_URL: ${{ vars.PUBLIC_BASE_URL }} PUBLIC_BASE_URL: ${{ vars.PUBLIC_BASE_URL }}
run: | run: |
TAG="${{ steps.meta.outputs.image_tag }}" $ErrorActionPreference = 'Stop'
docker build \ $tag = "${{ steps.meta.outputs.image_tag }}"
--build-arg NEXT_PUBLIC_API_URL="${PUBLIC_BASE_URL}/api" \ $base = $env:PUBLIC_BASE_URL
--build-arg NEXT_PUBLIC_APP_URL="${PUBLIC_BASE_URL}" \ docker build `
--build-arg NEXT_PUBLIC_APP_NAME="Dyolink" \ --build-arg "NEXT_PUBLIC_API_URL=$base/api" `
-t "${REGISTRY_PREFIX}/dyolink-frontend:${TAG}" \ --build-arg "NEXT_PUBLIC_APP_URL=$base" `
-t "${REGISTRY_PREFIX}/dyolink-frontend:latest" \ --build-arg "NEXT_PUBLIC_APP_NAME=Dyolink" `
-t "$env:REGISTRY_PREFIX/dyolink-frontend:$tag" `
-t "$env:REGISTRY_PREFIX/dyolink-frontend:latest" `
./frontend ./frontend
docker push "${REGISTRY_PREFIX}/dyolink-frontend:${TAG}" docker push "$env:REGISTRY_PREFIX/dyolink-frontend:$tag"
docker push "${REGISTRY_PREFIX}/dyolink-frontend:latest" docker push "$env:REGISTRY_PREFIX/dyolink-frontend:latest"
deploy: deploy:
needs: build-and-push needs: build-and-push
@@ -97,50 +107,61 @@ jobs:
steps: steps:
- name: Checkout (shallow clone from this Gitea — no gitea.com) - name: Checkout (shallow clone from this Gitea — no gitea.com)
run: | run: |
set -e $ErrorActionPreference = 'Stop'
SERVER="${{ github.server_url }}" $Server = "${{ github.server_url }}".TrimEnd('/')
SERVER="${SERVER%/}" $Repo = "${{ github.repository }}"
REPO="${{ github.repository }}" $Branch = "${{ github.ref_name }}"
BRANCH="${{ github.ref_name }}" $Token = "${{ github.token }}"
TOKEN="${{ github.token }}" $Actor = "${{ github.actor }}"
ACTOR="${{ github.actor }}" $hp = $Server -replace '^https?://', ''
HP="${SERVER#http://}" if ($Server.StartsWith('https')) {
HP="${HP#https://}" $cloneUrl = 'https://' + $Actor + ':' + $Token + '@' + $hp + '/' + $Repo + '.git'
if [[ "$SERVER" == https://* ]]; then } else {
CLONE_URL="https://${ACTOR}:${TOKEN}@${HP}/${REPO}.git" $cloneUrl = 'http://' + $Actor + ':' + $Token + '@' + $hp + '/' + $Repo + '.git'
else }
CLONE_URL="http://${ACTOR}:${TOKEN}@${HP}/${REPO}.git" $env:GIT_TERMINAL_PROMPT = '0'
fi git clone --depth 1 --branch $Branch $cloneUrl .
GIT_TERMINAL_PROMPT=0 git clone --depth 1 --branch "$BRANCH" "$CLONE_URL" .
- name: Write deploy.registry.env and validate secrets path - name: Write deploy.registry.env and validate secrets path
run: | run: |
SD='${{ vars.DEPLOY_SECRETS_DIR }}' $ErrorActionPreference = 'Stop'
if [ -z "$SD" ]; then $SD = '${{ vars.DEPLOY_SECRETS_DIR }}'.Trim()
echo "Set repository variable DEPLOY_SECRETS_DIR to the absolute path on this runner" if ([string]::IsNullOrWhiteSpace($SD)) {
echo "where database.staging.env and backend.staging.env live (not in git)." Write-Host "Set repository variable DEPLOY_SECRETS_DIR to the absolute path on this runner"
Write-Host "where database.staging.env and backend.staging.env live (not in git)."
exit 1 exit 1
fi }
test -f "${SD}/database.staging.env" || { echo "Missing ${SD}/database.staging.env"; exit 1; } if (-not (Test-Path (Join-Path $SD "database.staging.env"))) {
test -f "${SD}/backend.staging.env" || { echo "Missing ${SD}/backend.staging.env"; exit 1; } Write-Host "Missing $(Join-Path $SD 'database.staging.env')"
cd infrastructure exit 1
STAGING_PORT='${{ vars.STAGING_HTTP_PORT }}' }
STAGING_PORT="${STAGING_PORT:-8088}" if (-not (Test-Path (Join-Path $SD "backend.staging.env"))) {
{ Write-Host "Missing $(Join-Path $SD 'backend.staging.env')"
echo "REGISTRY_PREFIX=${{ vars.REGISTRY_HOST }}/${{ vars.REGISTRY_OWNER }}" exit 1
echo "IMAGE_TAG=${{ needs.build-and-push.outputs.image_tag }}" }
echo "STAGING_HTTP_PORT=${STAGING_PORT}" $stagingPort = '${{ vars.STAGING_HTTP_PORT }}'.Trim()
echo "DEPLOY_SECRETS_DIR=${SD}" if ([string]::IsNullOrWhiteSpace($stagingPort)) { $stagingPort = '8088' }
} > deploy.registry.env $imageTag = "${{ needs.build-and-push.outputs.image_tag }}"
$lines = @(
"REGISTRY_PREFIX=${{ vars.REGISTRY_HOST }}/${{ vars.REGISTRY_OWNER }}",
"IMAGE_TAG=$imageTag",
"STAGING_HTTP_PORT=$stagingPort",
"DEPLOY_SECRETS_DIR=$SD"
)
Set-Location infrastructure
$lines | Set-Content -Path deploy.registry.env -Encoding utf8
- name: Log in to container registry (for pull) - name: Log in to container registry (for pull)
run: | run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login "${{ vars.REGISTRY_HOST }}" \ $ErrorActionPreference = 'Stop'
-u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin $pass = @'
${{ secrets.REGISTRY_PASSWORD }}
'@
$pass.Trim() | docker login "${{ vars.REGISTRY_HOST }}" -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
- name: Pull and start stack - name: Pull and start stack
run: | run: |
set -e $ErrorActionPreference = 'Stop'
cd infrastructure Set-Location infrastructure
docker compose -f docker-compose.registry.yml --env-file deploy.registry.env pull backend frontend docker compose -f docker-compose.registry.yml --env-file deploy.registry.env pull backend frontend
docker compose -f docker-compose.registry.yml --env-file deploy.registry.env up -d docker compose -f docker-compose.registry.yml --env-file deploy.registry.env up -d

View File

@@ -86,6 +86,7 @@ Workflow file: **`.gitea/workflows/registry-build-deploy.yml`**.
- **Gitea Actions** enabled for the repository. - **Gitea Actions** enabled for the repository.
- A **self-hosted runner** (with Docker) registered to Gitea — the workflow uses `runs-on: self-hosted`. - A **self-hosted runner** (with Docker) registered to Gitea — the workflow uses `runs-on: self-hosted`.
- **Windows runners:** the workflow uses **PowerShell** (not Bash). Giteas runner was failing with `execvpe(/bin/bash) failed` when Bash was routed through WSL without a real `/bin/bash`. If your runner is **Linux**, switch `.gitea/workflows/registry-build-deploy.yml` to `defaults.run.shell: bash` and use Bash syntax instead.
- **Repository → Actions → Variables** (examples): - **Repository → Actions → Variables** (examples):
- `REGISTRY_HOST` — e.g. `178.131.50.201:3000` - `REGISTRY_HOST` — e.g. `178.131.50.201:3000`