From 9743096c32c932dc104dbe8b6e50dccc0cd63c7c Mon Sep 17 00:00:00 2001 From: kevin <1026838160@qq.com> Date: Sun, 14 Jan 2024 22:03:59 +0800 Subject: [PATCH] chore: add docker image --- .dockerignore | 13 +++++++++++++ .github/workflows/deploy.yml | 31 ++++++++++++++++++++++++++++++- Dockerfile | 23 +++++++++++++++++++++++ nginx.conf | 18 ++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cab4edd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +.dockerignore +.git + +_output/ +logs/ + +README.md +CONTRIBUTING.md + +docker-compose.yaml + +.github/ +.husky \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0e7362d..2e282ef 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -59,4 +59,33 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v2 \ No newline at end of file + uses: actions/deploy-pages@v2 + + docker: + needs: build + runs-on: ubuntu-latest + name: Build and Push Docker Image + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: | + kevlnlee/web-cicd-test:latest + kevlnlee/web-cicd-test:${{ env.GITHUB_REF##*/ }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2c46a6f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM node:20.11.0 as builder + +WORKDIR /app + +ADD . . + +RUN rm -rf node_modules +RUN npm install -g pnpm +RUN pnpm install +RUN pnpm run build + +FROM nginx + +WORKDIR /usr/share/nginx/html/ + +USER root + +COPY --from=builder /app/nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=builder /app/dist /usr/share/nginx/html/ + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..21ab5e8 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,18 @@ +server { + listen 80; + + gzip on; + gzip_min_length 1k; + gzip_comp_level 9; + gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml application/wasm; + gzip_vary on; + gzip_disable "MSIE [1-6]\."; + + default_type application/wasm; + + root /usr/share/nginx/html; + include /etc/nginx/mime.types; + location / { + try_files $uri /index.html; + } +} \ No newline at end of file