From 51e2c8782897f2b837730ae783c6997b942a29cc Mon Sep 17 00:00:00 2001 From: log101 Date: Sun, 23 Feb 2025 14:52:23 +0300 Subject: [PATCH] ci: add docker file and gitea action --- .gitea/workflows/static-deploy.yml | 66 ++++-------------------------- Dockerfile | 11 +++++ nginx/nginx.conf | 31 ++++++++++++++ 3 files changed, 49 insertions(+), 59 deletions(-) create mode 100644 Dockerfile create mode 100644 nginx/nginx.conf diff --git a/.gitea/workflows/static-deploy.yml b/.gitea/workflows/static-deploy.yml index cc7b3bb..6b510fc 100644 --- a/.gitea/workflows/static-deploy.yml +++ b/.gitea/workflows/static-deploy.yml @@ -1,70 +1,18 @@ -run-name: ${{ gitea.actor }}, deploy with ssh +run-name: ${{ gitea.actor }}, deploy to docker registry on: push: branches: - - "release" - -env: - BUILD_PATH: "." + - "main" jobs: build: - name: Build runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - - name: Detect package manager - id: detect-package-manager - run: | - if [ -f "${{ github.workspace }}/yarn.lock" ]; then - echo "manager=yarn" >> $GITHUB_OUTPUT - echo "command=install" >> $GITHUB_OUTPUT - echo "runner=yarn" >> $GITHUB_OUTPUT - echo "lockfile=yarn.lock" >> $GITHUB_OUTPUT - exit 0 - elif [ -f "${{ github.workspace }}/package.json" ]; then - echo "manager=npm" >> $GITHUB_OUTPUT - echo "command=ci" >> $GITHUB_OUTPUT - echo "runner=npx --no-install" >> $GITHUB_OUTPUT - echo "lockfile=package-lock.json" >> $GITHUB_OUTPUT - exit 0 - else - echo "Unable to determine package manager" - exit 1 - fi - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: "20" - cache: ${{ steps.detect-package-manager.outputs.manager }} - cache-dependency-path: ${{ env.BUILD_PATH }}/${{ steps.detect-package-manager.outputs.lockfile }} - - name: Install dependencies - run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} - working-directory: ${{ env.BUILD_PATH }} - - name: Make envfile - uses: SpicyPizza/create-envfile@v2.0 - with: - envkey_PUBLIC_BACKEND_HOST: ${{ vars.PUBLIC_BACKEND_HOST }} - - name: Build with Astro - run: | - ${{ steps.detect-package-manager.outputs.runner }} astro build - working-directory: ${{ env.BUILD_PATH }} - - name: Deploy to my server - id: deploy - uses: up9cloud/action-rsync@master - env: - USER: ${{ secrets.USERNAME }} - HOST: ${{ secrets.HOST }} - KEY: ${{ secrets.KEY }} - SOURCE: ./dist/ - TARGET: ${{ secrets.DESTINATION_FOLDER }} - ARGS: -avz --exclude=/.git/ - SSH_ARGS: "-p 22 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" - VERBOSE: true - - PRE_SCRIPT: | - echo start at: - date -u - POST_SCRIPT: "echo done at: && date -u" + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + push: ${{ github.event_name != 'pull_request' }} + tags: registry.container-registry:5000/log101-blog:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3616810 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM node:lts AS build +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build + +FROM nginx:alpine AS runtime +COPY ./nginx/nginx.conf /etc/nginx/nginx.conf +COPY --from=build /app/dist /usr/share/nginx/html +EXPOSE 8080 diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..43ead33 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,31 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + server { + listen 8080; + server_name _; + + root /usr/share/nginx/html; + index index.html index.htm; + include /etc/nginx/mime.types; + + gzip on; + gzip_min_length 1000; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript; + + error_page 404 /404.html; + location = /404.html { + root /usr/share/nginx/html; + internal; + } + + location / { + try_files $uri $uri/index.html =404; + } + } +}