init
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
name: Docker Build and Push
|
||||
description: Build, test, tag, and optionally push the Hamkar image
|
||||
inputs:
|
||||
image:
|
||||
description: Full OCI image name without a tag
|
||||
required: true
|
||||
branch:
|
||||
description: Human-readable image tag
|
||||
required: true
|
||||
commit_sha:
|
||||
description: Immutable commit image tag
|
||||
required: true
|
||||
push:
|
||||
description: Push both tags to the registry
|
||||
required: false
|
||||
default: "true"
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Build image
|
||||
shell: bash
|
||||
env:
|
||||
IMAGE: ${{ inputs.image }}
|
||||
BRANCH: ${{ inputs.branch }}
|
||||
COMMIT_SHA: ${{ inputs.commit_sha }}
|
||||
PUSH_IMAGE: ${{ inputs.push }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
go_proxy="${GOPROXY:-https://proxy.golang.org/}"
|
||||
output=(--load)
|
||||
if [[ "$PUSH_IMAGE" == "true" ]]; then
|
||||
output=(--push)
|
||||
fi
|
||||
|
||||
docker buildx build \
|
||||
-f Dockerfile \
|
||||
--build-arg "GO_PROXY=$go_proxy" \
|
||||
--label "org.opencontainers.image.revision=$COMMIT_SHA" \
|
||||
--label "org.opencontainers.image.source=${GITHUB_SERVER_URL:-}" \
|
||||
"${output[@]}" \
|
||||
-t "$IMAGE:$BRANCH" \
|
||||
-t "$IMAGE:$COMMIT_SHA" \
|
||||
.
|
||||
@@ -0,0 +1,27 @@
|
||||
name: Docker Login
|
||||
description: Log in to the OCI registry without exposing the password in process arguments
|
||||
inputs:
|
||||
registry:
|
||||
description: OCI registry hostname
|
||||
required: false
|
||||
default: oci.reg.darano.ir
|
||||
username:
|
||||
description: OCI registry username
|
||||
required: false
|
||||
default: admin
|
||||
password:
|
||||
description: OCI registry password
|
||||
required: true
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Log in
|
||||
shell: bash
|
||||
env:
|
||||
REGISTRY: ${{ inputs.registry }}
|
||||
REGISTRY_USERNAME: ${{ inputs.username }}
|
||||
REGISTRY_PASSWORD: ${{ inputs.password }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
printf '%s' "$REGISTRY_PASSWORD" |
|
||||
docker login "$REGISTRY" --username "$REGISTRY_USERNAME" --password-stdin
|
||||
@@ -0,0 +1,52 @@
|
||||
name: Select Go module proxy
|
||||
description: Select the fastest reachable Go module proxy for Docker builds
|
||||
inputs:
|
||||
go_mirrors:
|
||||
description: Newline-separated Go module proxies
|
||||
required: false
|
||||
default: |
|
||||
https://go.devneeds.ir/
|
||||
https://package-mirror.liara.ir/repository/go/
|
||||
https://go.reg.darano.ir/
|
||||
https://proxy.golang.org/
|
||||
outputs:
|
||||
go_proxy:
|
||||
description: Selected Go module proxy
|
||||
value: ${{ steps.select.outputs.go_proxy }}
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Select fastest reachable proxy
|
||||
id: select
|
||||
shell: bash
|
||||
env:
|
||||
GO_MIRRORS: ${{ inputs.go_mirrors }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
scores="$(mktemp)"
|
||||
fallback=""
|
||||
|
||||
while IFS= read -r mirror; do
|
||||
mirror="$(printf '%s' "$mirror" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
[[ -z "$mirror" || "$mirror" == \#* ]] && continue
|
||||
[[ -z "$fallback" ]] && fallback="$mirror"
|
||||
result="$(curl --location --silent --output /dev/null \
|
||||
--connect-timeout 3 --max-time 10 \
|
||||
--write-out '%{http_code} %{time_total}' "$mirror" 2>/dev/null || true)"
|
||||
read -r status duration <<< "$result"
|
||||
if [[ "$status" =~ ^(2|3)[0-9]{2}$ ]] && [[ "$duration" =~ ^[0-9]+([.][0-9]+)?$ ]]; then
|
||||
printf '%s\t%s\n' "$duration" "$mirror" >> "$scores"
|
||||
fi
|
||||
done <<< "$GO_MIRRORS"
|
||||
|
||||
if [[ -s "$scores" ]]; then
|
||||
go_proxy="$(sort -n -k1,1 "$scores" | head -n 1 | cut -f2-)"
|
||||
else
|
||||
go_proxy="$fallback"
|
||||
fi
|
||||
rm -f "$scores"
|
||||
|
||||
test -n "$go_proxy"
|
||||
echo "GOPROXY=$go_proxy" >> "$GITHUB_ENV"
|
||||
echo "go_proxy=$go_proxy" >> "$GITHUB_OUTPUT"
|
||||
echo "Selected Go proxy: $go_proxy"
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: Test and publish
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
IMAGE: oci.reg.darano.ir/personal/tracking-personel
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://git.darano.ir/actions/checkout@v5
|
||||
with:
|
||||
token: ${{ gitea.token }}
|
||||
path: ./
|
||||
|
||||
- name: Select package mirror
|
||||
uses: ./.gitea/actions/setup-mirrors
|
||||
|
||||
- name: Log in to registry
|
||||
if: gitea.event_name == 'push'
|
||||
uses: ./.gitea/actions/docker-login
|
||||
with:
|
||||
password: ${{ secrets.REG_PASS }}
|
||||
|
||||
- name: Build and test image
|
||||
uses: ./.gitea/actions/docker-build-push
|
||||
with:
|
||||
image: ${{ env.IMAGE }}
|
||||
branch: main
|
||||
commit_sha: ${{ gitea.sha }}
|
||||
push: ${{ gitea.event_name == 'push' }}
|
||||
Reference in New Issue
Block a user