Add Gitea deployment workflow
Some checks failed
Build and deploy Worker / build (push) Failing after 9m53s
Some checks failed
Build and deploy Worker / build (push) Failing after 9m53s
This commit is contained in:
70
.gitea/workflows/build-and-deploy.yml
Normal file
70
.gitea/workflows/build-and-deploy.yml
Normal file
@@ -0,0 +1,70 @@
|
||||
name: Build and deploy Worker
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: build-host
|
||||
env:
|
||||
SERVICE_NAME: worker
|
||||
IMAGE: gitea.dsrptlab.com/mapflow/worker:${{ github.sha }}
|
||||
DOKPLOY_APPLICATION_ID: WLVTwjBDqYy3vim88NyKX
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to Gitea registry
|
||||
run: |
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login gitea.dsrptlab.com \
|
||||
-u "${{ secrets.REGISTRY_USERNAME }}" \
|
||||
--password-stdin
|
||||
|
||||
- name: Build and push image
|
||||
run: |
|
||||
set -euo pipefail
|
||||
builder="mapflow-builder"
|
||||
if ! docker buildx inspect "$builder" >/dev/null 2>&1; then
|
||||
docker buildx create --name "$builder" --driver docker-container --buildkitd-config /etc/buildkit/buildkitd.toml
|
||||
fi
|
||||
docker buildx use "$builder"
|
||||
docker buildx inspect --bootstrap
|
||||
docker buildx build --push --tag "$IMAGE" .
|
||||
|
||||
- name: Skip stale deployment
|
||||
run: |
|
||||
set -euo pipefail
|
||||
latest_sha="$(git ls-remote origin refs/heads/main | awk '{print $1}')"
|
||||
if [ "$latest_sha" = "${GITHUB_SHA}" ]; then
|
||||
touch .deploy-current
|
||||
else
|
||||
echo "A newer main commit exists: $latest_sha. Skipping deploy for ${GITHUB_SHA}."
|
||||
fi
|
||||
|
||||
- name: Update Dokploy image
|
||||
run: |
|
||||
set -euo pipefail
|
||||
[ -f .deploy-current ] || exit 0
|
||||
payload=$(cat <<JSON
|
||||
{"applicationId":"$DOKPLOY_APPLICATION_ID","dockerImage":"$IMAGE","username":"${{ secrets.REGISTRY_USERNAME }}","password":"${{ secrets.REGISTRY_TOKEN }}","registryUrl":"gitea.dsrptlab.com"}
|
||||
JSON
|
||||
)
|
||||
curl -fsS -X POST "${{ secrets.DOKPLOY_URL }}/api/application.saveDockerProvider" \
|
||||
-H "x-api-key: ${{ secrets.DOKPLOY_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$payload"
|
||||
|
||||
- name: Deploy in Dokploy
|
||||
run: |
|
||||
set -euo pipefail
|
||||
[ -f .deploy-current ] || exit 0
|
||||
short_sha="${GITHUB_SHA:0:7}"
|
||||
payload=$(cat <<JSON
|
||||
{"applicationId":"$DOKPLOY_APPLICATION_ID","title":"$SERVICE_NAME #${GITHUB_RUN_NUMBER:-0} $short_sha","description":"Deploy registry image $IMAGE"}
|
||||
JSON
|
||||
)
|
||||
curl -fsS -X POST "${{ secrets.DOKPLOY_URL }}/api/application.deploy" \
|
||||
-H "x-api-key: ${{ secrets.DOKPLOY_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$payload"
|
||||
Reference in New Issue
Block a user