75 lines
2.5 KiB
YAML
75 lines
2.5 KiB
YAML
name: Build and deploy Flutter Web
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: build-host
|
|
env:
|
|
SERVICE_NAME: flutter
|
|
IMAGE: gitea.dsrptlab.com/mapflow/flutter:${{ github.sha }}
|
|
DOKPLOY_APPLICATION_ID: 9UR7Tpp9v_I6Ueu04sUiu
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Log in to Gitea registry
|
|
run: |
|
|
echo "${{ secrets.GITEA_TOKEN }}" | docker login gitea.dsrptlab.com \
|
|
-u "${{ github.actor }}" \
|
|
--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":"${{ github.actor }}","password":"${{ secrets.GITEA_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"
|