From e4112328b4184dd8f7ca2e93b06d3adce43378a8 Mon Sep 17 00:00:00 2001 From: Collin Bolles Date: Wed, 20 Nov 2024 16:15:19 -0500 Subject: [PATCH] feat: Deployment (#16) * Backend docker file * Frontend docker file + nginx config --- .github/workflows/backend.yaml | 44 ++++++++++++++++++++ .github/workflows/frontend.yaml | 44 ++++++++++++++++++++ packages/backend/Dockerfile | 16 +++++++ packages/backend/src/config/configuration.ts | 3 +- packages/backend/src/s3/s3.provider.ts | 3 +- packages/frontend/Dockerfile | 9 +--- packages/frontend/nginx.conf | 36 +++++++++++++++- 7 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 packages/backend/Dockerfile diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index 882f613..ab32d55 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -64,3 +64,47 @@ jobs: - name: Build run: npm run build + + docker: + name: Docker Build and Push + runs-on: ubuntu-latest + defaults: + run: + working-directory: packages/backend + steps: + - uses: docker/setup-qemu-action@v2 + - uses: docker/setup-buildx-action@v2 + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Docker Tags + id: meta + uses: docker/metadata-action@v4 + with: + images: | + hicsail/comets-backend + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + + - name: Login to Docker Hub + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build & Push Docker Build + uses: docker/build-push-action@v4 + with: + push: ${{ github.event_name != 'pull_request' }} + context: ./packages/backend + file: ./packages/runner/Dockerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha,scope=gateway + cache-to: type=gha,mode=max,scope=gateway + diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index e0049ae..dfb4243 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -64,3 +64,47 @@ jobs: - name: Build run: npm run build + + docker: + name: Docker Build and Push + runs-on: ubuntu-latest + defaults: + run: + working-directory: packages/frontend + steps: + - uses: docker/setup-qemu-action@v2 + - uses: docker/setup-buildx-action@v2 + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Docker Tags + id: meta + uses: docker/metadata-action@v4 + with: + images: | + hicsail/comets-frontend + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + + - name: Login to Docker Hub + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build & Push Docker Build + uses: docker/build-push-action@v4 + with: + push: ${{ github.event_name != 'pull_request' }} + context: ./packages/frontend + file: ./packages/runner/Dockerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha,scope=gateway + cache-to: type=gha,mode=max,scope=gateway + diff --git a/packages/backend/Dockerfile b/packages/backend/Dockerfile new file mode 100644 index 0000000..6672ec5 --- /dev/null +++ b/packages/backend/Dockerfile @@ -0,0 +1,16 @@ +FROM node:22 + +WORKDIR /usr/src/app + +# Install app dependencies +COPY package*.json ./ +RUN npm install + +# Copy over the source +COPY . . +RUN npm run build + +# Expore the default port +EXPOSE 3000 + +CMD ["npm", "run", "start:prod"] diff --git a/packages/backend/src/config/configuration.ts b/packages/backend/src/config/configuration.ts index fa75838..a53ad80 100644 --- a/packages/backend/src/config/configuration.ts +++ b/packages/backend/src/config/configuration.ts @@ -6,7 +6,8 @@ export default () => ({ accessID: process.env.S3_ACCESS_KEY_ID, accessSecret: process.env.S3_SECRET_ACCESS_KEY, endpoint: process.env.S3_ENDPOINT_URL, - bucket: process.env.S3_BUCKET + bucket: process.env.S3_BUCKET, + region: process.env.S3_REGION || 'us-east-1' }, runner: { image: process.env.RUNNER_IMAGE || 'hicsail/comets-runner:latest', diff --git a/packages/backend/src/s3/s3.provider.ts b/packages/backend/src/s3/s3.provider.ts index 7ce4ec2..a43a54d 100644 --- a/packages/backend/src/s3/s3.provider.ts +++ b/packages/backend/src/s3/s3.provider.ts @@ -13,7 +13,8 @@ export const s3Provider: Provider = { secretAccessKey: configService.getOrThrow('s3.accessSecret') }, endpoint: configService.getOrThrow('s3.endpoint'), - forcePathStyle: true + forcePathStyle: true, + region: configService.getOrThrow('s3.region') }); }, inject: [ConfigService] diff --git a/packages/frontend/Dockerfile b/packages/frontend/Dockerfile index 664d5e2..7518c72 100644 --- a/packages/frontend/Dockerfile +++ b/packages/frontend/Dockerfile @@ -1,12 +1,7 @@ -FROM node:18-alpine as builder - - +FROM node:18-alpine AS builder ARG VITE_COMETS_BACKEND -ARG VITE_COMETS_FLASK - -ENV VITE_COMETS_BACKEND ${VITE_COMETS_BACKEND} -ENV VITE_COMETS_FLASK ${VITE_COMETS_FLASK} +ENV VITE_COMETS_BACKEND=${VITE_COMETS_BACKEND} WORKDIR /usr/src/app COPY . . diff --git a/packages/frontend/nginx.conf b/packages/frontend/nginx.conf index 9ee04e0..b817462 100644 --- a/packages/frontend/nginx.conf +++ b/packages/frontend/nginx.conf @@ -15,6 +15,9 @@ events { } http { + # perl_modules /opt/app-root/etc/perl; + # perl_require Version.pm; + # perl_set $perl_version Version::installed; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' @@ -56,4 +59,35 @@ http { location = /50x.html { } } -} \ No newline at end of file + +# Settings for a TLS enabled server. +# +# server { +# listen 443 ssl http2 default_server; +# listen [::]:443 ssl http2 default_server; +# server_name _; +# root /opt/app-root/src; +# +# ssl_certificate "/etc/pki/nginx/server.crt"; +# ssl_certificate_key "/etc/pki/nginx/private/server.key"; +# ssl_session_cache shared:SSL:1m; +# ssl_session_timeout 10m; +# ssl_ciphers PROFILE=SYSTEM; +# ssl_prefer_server_ciphers on; +# +# # Load configuration files for the default server block. +# include /opt/app-root/etc/nginx.default.d/*.conf; +# +# location / { +# } +# +# error_page 404 /404.html; +# location = /40x.html { +# } +# +# error_page 500 502 503 504 /50x.html; +# location = /50x.html { +# } +# } + +}