From c96c23a7c5557716133761917974d97053ca6e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AB?= Date: Sun, 23 Aug 2026 14:24:47 +0000 Subject: [PATCH] feat: add CI/CD pipeline with Docker + Nginx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Gitea Actions workflow for auto-deploy on push to main - Add Dockerfile (nginx:alpine based, with layer caching) - Add nginx.conf (gzip, autoindex, static caching) - Add .dockerignore - Migrate cache.html → cache/index.html for directory-based routing --- .dockerignore | 4 ++++ .gitea/workflows/deploy.yaml | 33 +++++++++++++++++++++++++++++++++ Dockerfile | 18 ++++++++++++++++++ cache.html => cache/index.html | 0 nginx.conf | 29 +++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/deploy.yaml create mode 100644 Dockerfile rename cache.html => cache/index.html (100%) create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d326dba --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git +.gitea +LICENSE +README.md diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..1de34d8 --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,33 @@ +name: Deploy + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: aliyun + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build Docker Image + run: | + docker build \ + --cache-from illustrated-algorithm:latest \ + -t illustrated-algorithm:latest \ + . + + - name: Deploy Container + run: | + docker stop illustrated-algorithm 2>/dev/null || true + docker rm illustrated-algorithm 2>/dev/null || true + docker run -d \ + --name illustrated-algorithm \ + --restart unless-stopped \ + -p 10000:80 \ + illustrated-algorithm:latest + + - name: Cleanup Dangling Images + run: docker image prune -f diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fa61f3e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM nginx:alpine + +# Copy nginx config first (changes less often → cached layer) +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# Copy site content +COPY . /usr/share/nginx/html/ + +# Remove non-web files from the image +RUN rm -rf /usr/share/nginx/html/.git \ + /usr/share/nginx/html/.gitea \ + /usr/share/nginx/html/.dockerignore \ + /usr/share/nginx/html/Dockerfile \ + /usr/share/nginx/html/LICENSE \ + /usr/share/nginx/html/README.md + +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/cache.html b/cache/index.html similarity index 100% rename from cache.html rename to cache/index.html diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..366fdeb --- /dev/null +++ b/nginx.conf @@ -0,0 +1,29 @@ +server { + listen 80; + server_name _; + root /usr/share/nginx/html; + index index.html; + + # Gzip compression + gzip on; + gzip_types text/plain text/css application/javascript application/json image/svg+xml; + gzip_min_length 256; + + # Static assets caching + location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff2|ttf)$ { + expires 7d; + add_header Cache-Control "public, no-transform"; + } + + # Auto-index at root for listing available pages + location / { + autoindex on; + autoindex_exact_size off; + autoindex_localtime on; + } + + # Each subdirectory serves its page + location ~ ^/([^/]+)/ { + try_files $uri $uri/ /$1/index.html; + } +}