Skip to content

Commit

Permalink
Combined Docker container
Browse files Browse the repository at this point in the history
- Added support for a single container to run the backend and frontend from.
- Still allows for separate frontend and backend hostnames to allow for API Gateways.
  • Loading branch information
NickJongens committed Nov 26, 2024
1 parent 284a483 commit 1a5765d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 13 deletions.
60 changes: 60 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Use the official Node.js 22 image as the base
FROM node:22

# Set a root working directory
WORKDIR /usr/src/app

# Copy the .env file into the container for both frontend and backend
COPY .env .env

# -------- Backend Setup --------

# Set the working directory for the backend
WORKDIR /usr/src/app/keyfade-backend

# Copy backend package.json and package-lock.json
COPY keyfade-backend/package*.json ./

# Install backend dependencies
RUN npm install

# Copy the rest of the backend code
COPY keyfade-backend .

# -------- Frontend Setup --------

# Set the working directory for the frontend
WORKDIR /usr/src/app/keyfade-frontend

# Copy frontend package.json and package-lock.json
COPY keyfade-frontend/package*.json ./

# Install frontend dependencies
RUN npm install

# Copy the rest of the frontend code
COPY keyfade-frontend .

# Copy the .env file into the frontend directory (if required by build tools)
RUN cp /usr/src/app/.env /usr/src/app/keyfade-frontend/.env

# Build the frontend app
RUN npm run build

# Clean up unnecessary files
RUN rm -f /usr/src/app/keyfade-frontend/.env

# -------- Final Steps --------

# Set the working directory back to the root
WORKDIR /usr/src/app

# Expose both frontend and backend ports
EXPOSE 3001 3002

# Copy the start script
COPY start.sh /usr/src/app/start.sh
RUN chmod +x /usr/src/app/start.sh

# Start the applications using the start script
CMD ["/usr/src/app/start.sh"]
16 changes: 5 additions & 11 deletions keyfade-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This service is built using the following technologies:
TENANT_ID:
Your Azure Active Directory Tenant ID
KEY_VAULT_NAME:
Name of the Key Vault used for secure data storage (e.g., keyfade-kv)
Name of the Key Vault used for secure data storage without the full url

BACKEND_URL:
URL of the backend (e.g., https://demo-api.keyfade.com)
Expand All @@ -55,26 +55,19 @@ Build the container if you've made any changes or would like to ensure you have
docker build -t keyfade-backend:latest .
```

Or Use the publicly available backend container:
```
docker pull ghcr.io/nickjongens/keyfade-backend:latest
```

Docker Run:

```
docker run -d -p <port>:3002 \
```docker run -d -p <port>:3002 \
--name keyfade-backend \
-e TZ=Pacific/Auckland \
-e CLIENT_ID=<YOUR_CLIENT_ID> \
-e CLIENT_SECRET=<YOUR_CLIENT_SECRET> \
-e TENANT_ID=<YOUR_TENANT_ID> \
-e KEY_VAULT_NAME=<Azure_Key_Vault_Name \
-e KEY_VAULT_NAME=<YOUR_AZURE_KEY_VAULT> \
-e BACKEND_URL=https://demo-api.keyfade.com \
-e FRONTEND_URL=https://demo.keyfade.com \
-e HMAC_SECRET=<YOUR_HMAC_SECRET> \
-e WEBHOOK_URL=<YOUR_TEAMS_WEBHOOK_URL> \
ghcr.io/nickjongens/keyfade-backend:latest
keyfade-backend:latest
```

## Azure Key Vault Setup
Expand Down Expand Up @@ -104,3 +97,4 @@ There are no API permissions to be given here. These are provided in the Key Vau
- Run the containers within Azure Container Instances.



4 changes: 2 additions & 2 deletions keyfade-backend/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This service is built using the following technologies:
TENANT_ID:
Your Azure Active Directory Tenant ID
KEY_VAULT_NAME:
Name of the Key Vault used for secure data storage (e.g., keyfade-kv)
Name of the Key Vault used for secure data storage without the full url

BACKEND_URL:
URL of the backend (e.g., https://demo-api.keyfade.com)
Expand Down Expand Up @@ -62,7 +62,7 @@ Docker Run:
-e CLIENT_ID=<YOUR_CLIENT_ID> \
-e CLIENT_SECRET=<YOUR_CLIENT_SECRET> \
-e TENANT_ID=<YOUR_TENANT_ID> \
-e KEY_VAULT_NAME=keyfade-kv \
-e KEY_VAULT_NAME=<YOUR_AZURE_KEY_VAULT> \
-e BACKEND_URL=https://demo-api.keyfade.com \
-e FRONTEND_URL=https://demo.keyfade.com \
-e HMAC_SECRET=<YOUR_HMAC_SECRET> \
Expand Down
13 changes: 13 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Start the backend process
node /usr/src/app/keyfade-backend/index.js &

# Start the frontend process
npx serve -s /usr/src/app/keyfade-frontend/dist -l 3001 &

# Wait for any process to exit
wait -n

# Exit with the status of the process that exited first
exit $?

0 comments on commit 1a5765d

Please sign in to comment.