Skip to content

Commit 5764c56

Browse files
committed
Added Docker build workflow and updated Dockerfile
A new GitHub Actions workflow for building Docker images has been added. This workflow triggers on push events to the main branch. It builds a Docker image and pushes it to a specified repository. The Dockerfile has also been significantly refactored. The base image is now Node.js 16, and Nginx is used in the production stage to serve the built files. The application is built using npm ci for deterministic builds, and unnecessary environment variables have been removed.
1 parent ef307a9 commit 5764c56

File tree

2 files changed

+49
-40
lines changed

2 files changed

+49
-40
lines changed

.github/workflows/docker-build.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Docker Build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Build and Push Docker Image
15+
env:
16+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
17+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
18+
run: |
19+
docker build -t snjax/zeropool-docs:latest .
20+
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
21+
docker push snjax/zeropool-docs:latest

Dockerfile

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,29 @@
1-
## Base ########################################################################
2-
# Use a larger node image to do the build for native deps (e.g., gcc, python)
3-
FROM node:lts as base
4-
5-
# Reduce npm log spam and colour during install within Docker
6-
ENV NPM_CONFIG_LOGLEVEL=warn
7-
ENV NPM_CONFIG_COLOR=false
8-
9-
# We'll run the app as the `node` user, so put it in their home directory
10-
WORKDIR /home/node/app
11-
# Copy the source code over
12-
COPY --chown=node:node . /home/node/app/
13-
14-
## Development #################################################################
15-
# Define a development target that installs devDeps and runs in dev mode
16-
FROM base as development
17-
WORKDIR /home/node/app
18-
# Install (not ci) with dependencies, and for Linux vs. Linux Musl (which we use for -alpine)
19-
RUN npm install
20-
# Switch to the node user vs. root
21-
USER node
22-
# Expose port 3000
23-
EXPOSE 3000
24-
# Start the app in debug mode so we can attach the debugger
25-
CMD ["npm", "start"]
26-
27-
## Production ##################################################################
28-
# Also define a production target which doesn't use devDeps
29-
FROM base as production
30-
WORKDIR /home/node/app
31-
COPY --chown=node:node --from=development /home/node/app/node_modules /home/node/app/node_modules
32-
# Build the Docusaurus app
1+
# Use Node.js as the base image for building the application
2+
FROM node:16 AS builder
3+
4+
# Set the working directory inside the container
5+
WORKDIR /app
6+
7+
# Copy package.json and package-lock.json to the working directory
8+
COPY package*.json ./
9+
10+
# Install dependencies using npm ci for a deterministic build
11+
RUN npm ci
12+
13+
# Copy the rest of the project files to the working directory
14+
COPY . .
15+
16+
# Build the Docusaurus application
3317
RUN npm run build
34-
CMD ["npm", "run", "serve_prod"]
35-
36-
## Deploy ######################################################################
37-
# Use a stable nginx image
38-
FROM nginx:stable-alpine as deploy
39-
WORKDIR /home/node/app
40-
# Copy what we've installed/built from production
41-
COPY --chown=node:node --from=production /home/node/app/build /usr/share/nginx/html/
18+
19+
# Use Nginx as the base image for the production stage
20+
FROM nginx:alpine
21+
22+
# Copy the built files from the previous stage to the Nginx html directory
23+
COPY --from=builder /app/build /usr/share/nginx/html
24+
25+
# Expose port 80 to allow incoming HTTP traffic
26+
EXPOSE 80
27+
28+
# Run Nginx in the foreground when the container starts
29+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)