From 20d2e0b20a742307ba562e10769c3ec6a42e8c08 Mon Sep 17 00:00:00 2001 From: Jens Reidel Date: Sun, 19 May 2024 17:21:43 +0200 Subject: [PATCH] Add docker builds Signed-off-by: Jens Reidel --- .github/workflows/build-docker-image.yml | 35 ++++++++++++++++++ .github/workflows/check.yml | 17 --------- .github/workflows/deploy.yml | 29 --------------- Dockerfile | 15 ++++++++ nginx.conf | 46 ++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/build-docker-image.yml delete mode 100644 .github/workflows/check.yml delete mode 100644 .github/workflows/deploy.yml create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml new file mode 100644 index 0000000..a82c485 --- /dev/null +++ b/.github/workflows/build-docker-image.yml @@ -0,0 +1,35 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main # Adjust this to your main branch + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + build-args: | + VITE_API_HOSTNAME="https://lineage-downloads.mainlining.org/" + tags: | + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:${{ github.sha }} diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml deleted file mode 100644 index 90d752d..0000000 --- a/.github/workflows/check.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: check - -on: [push, pull_request] - -jobs: - check: - runs-on: ubuntu-latest - - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Run [ci, lint, format] - run: | - npm ci - npm run lint - npm run format -- --check --no-write diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 1bd69aa..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Deploy to Fly -on: - push: - branches: - - main -jobs: - deploy: - name: Deploy - runs-on: ubuntu-latest - steps: - # This step checks out a copy of your repository. - - uses: actions/checkout@v2 - # This step runs `flyctl deploy`. - - uses: superfly/flyctl-actions@master - env: - FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - with: - args: "deploy" - notify: - name: Notify - runs-on: ubuntu-latest - needs: - - deploy - if: ${{ always() }} - steps: - - uses: nobrayner/discord-webhook@v1 - with: - github-token: ${{ secrets.github_token }} - discord-webhook: ${{ secrets.DISCORD_WEBHOOK }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fed1cd6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM docker.io/library/alpine:edge AS builder +ARG VITE_API_HOSTNAME + +RUN apk add --no-cache nodejs-current npm + +WORKDIR /src +COPY . . + +RUN echo "VITE_API_HOSTNAME=${VITE_API_HOSTNAME}" > .env.local && \ + npm run build + +FROM docker.io/library/nginx:alpine + +COPY --from=builder /src/dist /dist +COPY nginx.conf /etc/nginx/nginx.conf diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..01d5876 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,46 @@ +user nginx; +worker_processes auto; + +error_log /dev/stderr; # Redirect error logs to stderr +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /dev/stdout main; # Redirect access logs to stdout + + sendfile on; + + keepalive_timeout 65; + + server { + listen 80 default; + real_ip_header X-Real-IP; + real_ip_recursive on; + set_real_ip_from 0.0.0.0/0; + + root /dist/; + index index.html index.htm; + gzip on; + gzip_disable "msie6"; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_buffers 15 8k; + gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript; + location ~* \.(?:css|js|png)$ { + expires 1d; + add_header Cache-Control "public"; + } + } +}