diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5d1b033 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules +dist +.git +.gitignore +*.md +eslint.config.js +vite.config.js diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml new file mode 100644 index 0000000..d503a82 --- /dev/null +++ b/.gitea/workflows/docker.yml @@ -0,0 +1,42 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + +env: + REGISTRY: git.danhenry.dev + IMAGE_NAME: git.danhenry.dev/thelab/work-queue-webui + +jobs: + build-and-push: + 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 Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.DOCKER_REGISTRY_USER }} + password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} + + - name: Extract commit SHA + run: echo "SHA=${GITEA_SHA:0:7}" >> $GITHUB_ENV + + - name: Build and push multi-arch image + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ${{ env.IMAGE_NAME }}:${{ env.SHA }} + ${{ env.IMAGE_NAME }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..994fd98 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Stage 1: Build the React app +FROM node:22-alpine AS builder + +WORKDIR /app + +COPY package*.json ./ +RUN npm ci + +COPY . . +RUN npm run build + +# Stage 2: Serve with nginx +FROM nginx:alpine + +COPY --from=builder /app/dist /usr/share/nginx/html +COPY --from=builder /app/docker/nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 443 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..0f83ac8 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,16 @@ +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { + expires 1y; + add_header Cache-Control "public, immutable"; + } +}