From 1966e0059cbce56a813fd870cf11638c0486c7c2 Mon Sep 17 00:00:00 2001 From: Lumither Tao Date: Mon, 3 Nov 2025 01:54:28 -0500 Subject: [PATCH] feat(action) add release build --- .github/workflows/canary-build.yml | 2 +- .github/workflows/release-build.yml | 64 +++++++++++++++++++++++++++++ dev.compose.yaml | 4 +- prod.cr.compose.yaml | 54 ++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/release-build.yml create mode 100644 prod.cr.compose.yaml diff --git a/.github/workflows/canary-build.yml b/.github/workflows/canary-build.yml index 5de6093..5313955 100644 --- a/.github/workflows/canary-build.yml +++ b/.github/workflows/canary-build.yml @@ -2,7 +2,7 @@ name: build canary nocturne image on: push: branches: - - dev + - master env: REGISTRY: cr.lmt.moe diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml new file mode 100644 index 0000000..34db16a --- /dev/null +++ b/.github/workflows/release-build.yml @@ -0,0 +1,64 @@ +name: build release nocturne image +on: + push: + branches: + - release + +env: + REGISTRY: cr.lmt.moe + TAG: release + PROJECT: nocturne + + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: setup builder + uses: docker/setup-buildx-action@v3 + + - name: registry login + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: build containers + run: | + make build + + - name: tag and push + run: | + PROJECT_NAME=$(basename "$PWD") + + ALL_IMAGES=$(docker compose -f prod.compose.yaml config --services 2>/dev/null) + PULLED_IMAGES=$(docker compose -f prod.compose.yaml config 2>/dev/null \ + | awk '/image:/ {print $2}' \ + | sort -u \ + | sed 's/:.*//' \ + ) + TO_PUSH=$(comm -23 \ + <(echo "$ALL_IMAGES" | sort) \ + <(echo "$PULLED_IMAGES") \ + ) + + FMT_STRING=$(echo "$TO_PUSH" | xargs printf '%s, ' | sed 's/, $//') + echo "services to push: $FMT_STRING" + + for SERVICE in $TO_PUSH; do + LOCAL_TAG="${PROJECT_NAME}-${SERVICE}:latest" + REMOTE_TAG="${REGISTRY}/${PROJECT}/${SERVICE}:${TAG}" + + if docker image inspect "$LOCAL_TAG" >/dev/null 2>&1; then + echo "Pushing $REMOTE_TAG" + docker tag "$LOCAL_TAG" "$REMOTE_TAG" + docker push "$REMOTE_TAG" + else + echo "warn: image $LOCAL_TAG not found, skipping $SERVICE" + fi + + done diff --git a/dev.compose.yaml b/dev.compose.yaml index a8c89b9..00bd733 100644 --- a/dev.compose.yaml +++ b/dev.compose.yaml @@ -27,10 +27,10 @@ services: - ./blog_posts_git:/app/blog_posts_git:ro env_file: - ./container/dev/.env - + postgres: image: postgres:16.3 ports: - - 5432:5432 + - "5432:5432" env_file: - ./container/dev/.env diff --git a/prod.cr.compose.yaml b/prod.cr.compose.yaml new file mode 100644 index 0000000..58d7a71 --- /dev/null +++ b/prod.cr.compose.yaml @@ -0,0 +1,54 @@ +services: + frontend: + depends_on: + - backend + image: cr.lmt.moe/nocturne/frontend:${TAG} + restart: always + ports: + - "0.0.0.0:3000:3000" + env_file: + - ./.env + + + backend: + depends_on: + - migrate + image: cr.lmt.moe/nocturne/backend:${TAG} + restart: always + ports: + - "0.0.0.0:3001:3001" + env_file: + - ./.env + - ./.env.local + dns: + - 1.1.1.1 + + + migrate: + image: postgres:17 + depends_on: + postgres: + condition: service_healthy + env_file: + - ./.env + - ./.env.local + volumes: + - ./migration/ddl:/migrations:ro + - ./migration/migration.sh:/migration.sh:ro + entrypoint: [ "/bin/sh", "/migration.sh" ] + + + postgres: + image: postgres:17 + ports: + - "5432:5432" + env_file: + - ./.env + - ./.env.local + healthcheck: + test: [ "CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB" ] + interval: 5s + timeout: 3s + retries: 10 + start_period: 5s + restart: always