Skip to content

Commit

Permalink
Merge pull request #266 from UoaWDCC/feat/deployment
Browse files Browse the repository at this point in the history
Feat/deployment
  • Loading branch information
nroh555 authored Oct 20, 2024
2 parents 4387903 + a0f2dc3 commit 3e455f9
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/deploy.staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Fly Deploy Staging

on:
push:
branches:
- main

jobs:
deploy-web:
name: Deploy Web
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only --config fly.staging.toml --build-secret VITE_FIREBASE_PROJECT_ID=${{ secrets.VITE_FIREBASE_PROJECT_ID }} --build-secret VITE_REACT_APP_API_KEY=${{ secrets.VITE_REACT_APP_API_KEY }} --build-secret VITE_REACT_APP_AUTH_DOMAIN=${{ secrets.VITE_REACT_APP_AUTH_DOMAIN }} --build-secret VITE_REACT_APP_STORAGE_BUCKET=${{ secrets.VITE_REACT_APP_STORAGE_BUCKET }} --build-secret VITE_REACT_APP_MESSAGING_SENDER_ID=${{ secrets.VITE_REACT_APP_MESSAGING_SENDER_ID }} --build-secret VITE_REACT_APP_APP_ID=${{ secrets.VITE_REACT_APP_APP_ID }} --build-secret VITE_REACT_APP_MEASUREMENT_ID=${{ secrets.VITE_REACT_APP_MEASUREMENT_ID }}
working-directory: ./frontend
env:
FLY_API_TOKEN: ${{ secrets.FLY_STAGING_API_TOKEN }}

deploy-api:
name: Deploy Api
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only --config fly.staging.toml
working-directory: ./backend
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_STAGING_API_TOKEN }}
1 change: 1 addition & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
41 changes: 41 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# syntax = docker/dockerfile:1
# Adjust NODE_VERSION as desired
ARG NODE_VERSION=18.19.0
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Node.js"

# Node.js app lives here
WORKDIR /app

# Set production environment
ARG YARN_VERSION=1.22.21
RUN npm install -g yarn@$YARN_VERSION --force

# Throw-away build stage to reduce size of final image
FROM base as install

# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3

# Install node modules
COPY --link package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# Copy application code
COPY --link . .

FROM base as build

COPY --from=install /app /app

# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
EXPOSE 5000
CMD [ "yarn", "run", "start" ]
18 changes: 18 additions & 0 deletions backend/fly.staging.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
app = 'wdcc-vps-api-staging'
primary_region = 'syd'

[build]
dockerfile = "Dockerfile"

[http_service]
internal_port = 5000
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
cpu_kind = 'shared'
cpus = 1
memory_mb = 1024
3 changes: 3 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
node_modules
.env
1 change: 1 addition & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# production
/build
/dist

# environment
.env
Expand Down
65 changes: 65 additions & 0 deletions frontend/Dockerfile.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=18.19.0
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Vite"

# Vite app lives here
WORKDIR /app

ARG YARN_VERSION=1.22.21
RUN npm install -g yarn@$YARN_VERSION --force

# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3

# Install node modules
COPY --link package.json yarn.lock ./
RUN yarn install --frozen-lockfile --production=false

# Copy application code
COPY --link . .

# Set environment variables for Firebase and Clerk
ARG VITE_FIREBASE_PROJECT_ID
ARG VITE_REACT_APP_API_KEY
ARG VITE_REACT_APP_AUTH_DOMAIN
ARG VITE_REACT_APP_STORAGE_BUCKET
ARG VITE_REACT_APP_MESSAGING_SENDER_ID
ARG VITE_REACT_APP_APP_ID
ARG VITE_REACT_APP_MEASUREMENT_ID

ENV VITE_FIREBASE_PROJECT_ID=${VITE_FIREBASE_PROJECT_ID}
ENV VITE_REACT_APP_API_KEY=${VITE_REACT_APP_API_KEY}
ENV VITE_REACT_APP_AUTH_DOMAIN=${VITE_REACT_APP_AUTH_DOMAIN}
ENV VITE_REACT_APP_STORAGE_BUCKET=${VITE_REACT_APP_STORAGE_BUCKET}
ENV VITE_REACT_APP_MESSAGING_SENDER_ID=${VITE_REACT_APP_MESSAGING_SENDER_ID}
ENV VITE_REACT_APP_APP_ID=${VITE_REACT_APP_APP_ID}
ENV VITE_REACT_APP_MEASUREMENT_ID=${VITE_REACT_APP_MEASUREMENT_ID}

# Set server URL
ENV VITE_REACT_APP_SERVER_URL="https://wdcc-vps-api-staging.fly.dev"

# Build the app with environment variables
RUN yarn run build

# Remove development dependencies
RUN yarn install --production=true

# Final stage for app image
FROM nginx

# Copy built application
COPY --from=build /app/dist /usr/share/nginx/html
COPY --link _redirects /usr/share/nginx/html/_redirects
COPY nginx.conf /etc/nginx/nginx.conf

# Start the server by default, this can be overwritten at runtime
EXPOSE 80
CMD [ "/usr/sbin/nginx", "-g", "daemon off;" ]
1 change: 1 addition & 0 deletions frontend/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* /index.html 200
19 changes: 19 additions & 0 deletions frontend/fly.staging.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
app = 'wdcc-vps-staging'
primary_region = 'syd'

[build]
# dockerfile contains build time non-sensitive env vars
dockerfile = "Dockerfile.staging"

[http_service]
internal_port = 80
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
cpu_kind = 'shared'
cpus = 1
memory_mb = 1024
24 changes: 24 additions & 0 deletions frontend/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
worker_processes auto;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

server {
listen 80;

root /usr/share/nginx/html;
index index.html;

location / {
try_files $uri $uri/ /index.html;
}
}
}
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"react-dom": "^17.0.2",
"react-firebase-hooks": "^3.0.4",
"react-flow-renderer": "^10.3.16",
"react-hot-toast": "^2.4.1",
"react-moveable": "0.29.0",
"react-router-dom": "^5.2.0",
"typescript": "^4.3.5",
Expand Down
12 changes: 12 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3255,6 +3255,11 @@ globalthis@^1.0.3:
define-properties "^1.2.1"
gopd "^1.0.1"

goober@^2.1.10:
version "2.1.16"
resolved "https://registry.yarnpkg.com/goober/-/goober-2.1.16.tgz#7d548eb9b83ff0988d102be71f271ca8f9c82a95"
integrity sha512-erjk19y1U33+XAMe1VTvIONHYoSqE4iS7BYUZfHaqeohLmnC0FdxEh7rQU+6MZ4OajItzjZFSRtVANrQwNq6/g==

gopd@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/gopd/-/gopd-1.0.1.tgz#29ff76de69dac7489b7c0918a5788e56477c332c"
Expand Down Expand Up @@ -4413,6 +4418,13 @@ react-flow-renderer@^10.3.16:
d3-zoom "^3.0.0"
zustand "^3.7.2"

react-hot-toast@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/react-hot-toast/-/react-hot-toast-2.4.1.tgz#df04295eda8a7b12c4f968e54a61c8d36f4c0994"
integrity sha512-j8z+cQbWIM5LY37pR6uZR6D4LfseplqnuAO4co4u8917hBUvXlEqyP1ZzqVLcqoyUesZZv/ImreoCeHVDpE5pQ==
dependencies:
goober "^2.1.10"

"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.0.0, react-is@^18.3.1:
version "18.3.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e"
Expand Down

0 comments on commit 3e455f9

Please sign in to comment.