From bd7ac3367ff0bb871336571b13573f0b6283de3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E5=85=83=E7=9A=93?= Date: Sun, 18 May 2025 16:11:07 +0800 Subject: [PATCH] Update caching & docker compose --- .github/workflows/build_docker_image.yml | 53 ++++++++++++++++++++++++ .github/workflows/self_deploy.yml | 34 --------------- docker-compose.yml | 24 ++++++----- new-docker-compose.yml | 29 ------------- nuxt.config.ts | 1 + 5 files changed, 68 insertions(+), 73 deletions(-) create mode 100644 .github/workflows/build_docker_image.yml delete mode 100644 .github/workflows/self_deploy.yml delete mode 100755 new-docker-compose.yml diff --git a/.github/workflows/build_docker_image.yml b/.github/workflows/build_docker_image.yml new file mode 100644 index 0000000..253f924 --- /dev/null +++ b/.github/workflows/build_docker_image.yml @@ -0,0 +1,53 @@ +name: Build and Push Docker Image + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=sha,prefix= + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/self_deploy.yml b/.github/workflows/self_deploy.yml deleted file mode 100644 index 9790571..0000000 --- a/.github/workflows/self_deploy.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Server Deployment Request -on: - push: - branches: - - master - workflow_dispatch: - -jobs: - deploy: - runs-on: ubuntu-latest - - env: - DEPLOY_URL: ${{ secrets.DEPLOY_URL }} - - steps: - - name: Send deployment request - id: deploy-request - run: | - echo "Sending deployment request to server..." - RESPONSE=$(curl -X POST \ - -H "Content-Type: application/json" \ - --http1.1 \ - --fail \ - --silent \ - --show-error \ - "${{ secrets.DEPLOY_URL }}" || echo "Failed to send request") - - if [ $? -eq 0 ]; then - echo "Deployment request sent successfully" - echo "Response: $RESPONSE" - else - echo "Error sending deployment request" - exit 1 - fi diff --git a/docker-compose.yml b/docker-compose.yml index 41c4a4e..58f0342 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,19 @@ -version: "3.8" - services: newsanalyze-service: - build: . - ports: - - "127.0.0.1:36694:3000" - environment: - - NODE_ENV=production - restart: unless-stopped + image: ghcr.io/hpware/news-analyze:latest healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3000"] - interval: 30s + test: ["CMD", "curl", "-f", "http://localhost:3000/health"] + interval: 1m timeout: 10s retries: 3 + networks: + - app-network + labels: + - "traefik.enable=true" + - "traefik.http.routers.newsanalyze.rule=Host(`news.yuanhau.com`)" + - "traefik.http.routers.newsanalyze.entrypoints=webinternal" + - "traefik.http.services.newsanalyze.loadbalancer.server.port=3000" + +networks: + web: + external: true diff --git a/new-docker-compose.yml b/new-docker-compose.yml deleted file mode 100755 index 0063c38..0000000 --- a/new-docker-compose.yml +++ /dev/null @@ -1,29 +0,0 @@ -services: - internal-proxy: - image: traefik:latest - command: - - --entrypoints.webinternal.address=:80 - ports: - - "127.0.0.1:36694:80" - volumes: - - /var/run/docker.sock:/var/run/docker.sock:ro - networks: - - app-network - newsanalyze-service: - build: . - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3000/health"] - interval: 1m - timeout: 10s - retries: 3 - networks: - - app-network - labels: - - "traefik.enable=true" - - "traefik.http.routers.newsanalyze.rule=Host(`news.yuanhau.com`)" - - "traefik.http.routers.newsanalyze.entrypoints=webinternal" - - "traefik.http.services.newsanalyze.loadbalancer.server.port=3000" - -networks: - app-network: - driver: bridge diff --git a/nuxt.config.ts b/nuxt.config.ts index 3ad7eb5..58b03ec 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -18,6 +18,7 @@ export default defineNuxtConfig({ redirect: "https://s3.yhw.tw/data/def-zip-bomb/wp-login.php.zip", }, "/api/cached/**": { swr: 3600 }, + "/api/news/get": { swr: 3600 }, }, css: ["~/styles/main.css"],