From 0fe7140380546f3be080c6fc6e309ba5f220cf35 Mon Sep 17 00:00:00 2001 From: log101 Date: Sat, 8 Jun 2024 01:54:24 +0300 Subject: [PATCH] ci: add docker files --- .gitea/workflows/astro-deploy.yaml | 73 ------------------------------ Dockerfile | 28 ++++++++++++ astro.config.mjs | 3 +- docker-compose.yml | 8 ++++ 4 files changed, 37 insertions(+), 75 deletions(-) delete mode 100644 .gitea/workflows/astro-deploy.yaml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.gitea/workflows/astro-deploy.yaml b/.gitea/workflows/astro-deploy.yaml deleted file mode 100644 index f7a9b64..0000000 --- a/.gitea/workflows/astro-deploy.yaml +++ /dev/null @@ -1,73 +0,0 @@ -run-name: ${{ gitea.actor }}, deploy with ssh -on: [push] - -env: - BUILD_PATH: "." - - -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: Build with Astro - run: | - ${{ steps.detect-package-manager.outputs.runner }} astro build - working-directory: ${{ env.BUILD_PATH }} - - name: Deploy to my server - uses: up9cloud/action-rsync@master - env: - HOST: ${{ secrets.HOST }} - KEY: ${{ secrets.KEY }} - TARGET: ${{ secrets.DESTINATION_FOLDER }} - - VERBOSE: true - USER: ${{ secrets.USERNAME }} - ARGS: -az --exclude=/.git/ - SSH_ARGS: '-p 22 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' - SOURCE: ./dist/ - - PRE_SCRIPT: | - echo start at: - date -u - POST_SCRIPT: "echo done at: && date -u" - - name: Send mail - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - key: ${{ secrets.KEY }} - port: ${{ secrets.PORT }} - script: | - echo -e "Subject: Act Runner Report: ${{ job.status}}\nFrom: gitea@log101.dev\n\nJob has finished with status ${{ job.status }}\n${{ github.repository }}: [${{ github.ref }}@${{ github.sha }}](${{ github.server_url }}/${{ github.repository }}/actions)" | sendmail ffrknerdm@gmail.com - diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c1391b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# Stage 1: Build the Astro project +FROM node:20-alpine AS builder + +WORKDIR /app + +# Copy package.json and package-lock.json files +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy the rest of the application files +COPY . . + +# Build the Astro project +RUN npm run build + +# Stage 2: Serve with nginx +FROM nginx:alpine + +# Copy the built static files from the builder stage +COPY --from=builder /app/dist /usr/share/nginx/html + +# Copy custom nginx configuration file if needed +# COPY nginx.conf /etc/nginx/nginx.conf + +# Expose port 80 to the outside world +EXPOSE 80 diff --git a/astro.config.mjs b/astro.config.mjs index 44be27e..3f2d287 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -4,8 +4,7 @@ import tailwind from "@astrojs/tailwind"; // https://astro.build/config export default defineConfig({ - site: "https://log101.dev", - base: "/blog", + site: "https://blog.log101.dev", integrations: [ tailwind({ applyBaseStyles: false, diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..49e9fd5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: "3.8" + +services: + astro: + image: registry.log101.dev/astro-nginx:latest + ports: + - "47543:80" + restart: unless-stopped