demo-app/.gitea/workflows/deploy.yml
ningning 18fdd9176a
Some checks failed
Build and deploy demo app / deploy (push) Failing after 3s
fix: avoid external checkout action
2026-06-26 12:06:07 +08:00

90 lines
2.4 KiB
YAML

name: Build and deploy demo app
on:
push:
branches:
- main
workflow_dispatch:
env:
APP_NAME: demo-app
DEPLOY_DIR: /workspace/apps/demo-app
REGISTRY: localhost:5001
IMAGE_NAME: localhost:5001/${{ github.repository }}
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
run: |
set -eu
git clone "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" .
git checkout "$GITHUB_SHA"
- name: Show context
run: |
set -eu
echo "repository=${{ github.repository }}"
echo "sha=${{ github.sha }}"
docker version
- name: Build image
run: |
set -eu
docker build \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
-t "$IMAGE_NAME:${{ github.sha }}" \
-t "$IMAGE_NAME:latest" \
.
- name: Push image
run: |
set -eu
docker push "$IMAGE_NAME:${{ github.sha }}"
docker push "$IMAGE_NAME:latest"
- name: Deploy with local Docker Compose
run: |
set -eu
mkdir -p "$DEPLOY_DIR"
cat > "$DEPLOY_DIR/docker-compose.yml" <<EOF
services:
demo-app:
image: $IMAGE_NAME:${{ github.sha }}
container_name: local-demo-app
env_file:
- .env
ports:
- "8088:8080"
restart: unless-stopped
EOF
if [ ! -f "$DEPLOY_DIR/.env" ]; then
cat > "$DEPLOY_DIR/.env" <<EOF
APP_NAME=demo-app
APP_VERSION=${{ github.sha }}
PORT=8080
EOF
else
if grep -q '^APP_VERSION=' "$DEPLOY_DIR/.env"; then
sed -i "s/^APP_VERSION=.*/APP_VERSION=${{ github.sha }}/" "$DEPLOY_DIR/.env"
else
printf '\nAPP_VERSION=%s\n' "${{ github.sha }}" >> "$DEPLOY_DIR/.env"
fi
fi
docker compose -f "$DEPLOY_DIR/docker-compose.yml" pull
docker compose -f "$DEPLOY_DIR/docker-compose.yml" up -d
- name: Health check
run: |
set -eu
for i in $(seq 1 30); do
if curl -fsS http://host.docker.internal:8088/health; then
exit 0
fi
sleep 2
done
docker compose -f "$DEPLOY_DIR/docker-compose.yml" ps
docker logs local-demo-app --tail=100 || true
exit 1