Update caching & docker compose

This commit is contained in:
吳元皓 2025-05-18 16:11:07 +08:00
parent 8975812447
commit bd7ac3367f
5 changed files with 68 additions and 73 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"],