From f3a746ea41e11c4cbc32a400d2b0eea09b13ac55 Mon Sep 17 00:00:00 2001 From: Lars Hampe Date: Sat, 17 Aug 2024 17:28:23 +0200 Subject: [PATCH] feat: add docker build and push --- .dockerignore | 3 +++ .gitea/workflows/main.yaml | 42 ++++++++++++++++++++++++++++++++++++++ Dockerfile | 12 +++++++++++ nginx/nginx.conf | 31 ++++++++++++++++++++++++++++ package.json | 6 ++++-- 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/main.yaml create mode 100644 Dockerfile create mode 100644 nginx/nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a44058c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.DS_Store +node_modules +dist \ No newline at end of file diff --git a/.gitea/workflows/main.yaml b/.gitea/workflows/main.yaml new file mode 100644 index 0000000..554770a --- /dev/null +++ b/.gitea/workflows/main.yaml @@ -0,0 +1,42 @@ +name: Build and Push Docker Image +run-name: ${{ gitea.actor }} +on: + push: + branches: + - main + +jobs: + BuildAndPush: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set docker chmod (temp solution) + run: sudo chmod 666 /var/run/docker.sock + + - name: Docker - Login + uses: docker/login-action@v1 + with: + registry: git.hashdot.co + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Use Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.1.21 + + - name: Install dependencies + run: bun install + + - name: Build + run: bun run build + + - name: Build Docker Image + run: bun run docker:build + + - name: Push Docker Image + run: bun run docker:push diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c2c84bf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM oven/bun:1 as build +WORKDIR /app +COPY . . + +RUN bun install +RUN bun 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 \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..a1a6187 --- /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; + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 8282eb1..fe50a4a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "start": "astro dev", "build": "astro check && astro build", "preview": "astro preview", - "astro": "astro" + "astro": "astro", + "docker:build": "docker build -t git.hashdot.co/hashdot/website .", + "docker:push": "docker push git.hashdot.co/hashdot/website" }, "dependencies": { "@astrojs/check": "^0.9.2", @@ -20,4 +22,4 @@ "tailwindcss": "^3.4.10", "typescript": "^5.5.4" } -} \ No newline at end of file +}