Skip to content

Commit

Permalink
Added Docker build workflow and updated Dockerfile
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
snjax committed Apr 18, 2024
1 parent ef307a9 commit 23dd45d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Docker Build

on:
push:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Build and Push Docker Image
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
docker build -t snjax/zeropool-docs:latest .
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
docker push snjax/zeropool-docs:latest:latest
68 changes: 28 additions & 40 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
## Base ########################################################################
# Use a larger node image to do the build for native deps (e.g., gcc, python)
FROM node:lts as base

# Reduce npm log spam and colour during install within Docker
ENV NPM_CONFIG_LOGLEVEL=warn
ENV NPM_CONFIG_COLOR=false

# We'll run the app as the `node` user, so put it in their home directory
WORKDIR /home/node/app
# Copy the source code over
COPY --chown=node:node . /home/node/app/

## Development #################################################################
# Define a development target that installs devDeps and runs in dev mode
FROM base as development
WORKDIR /home/node/app
# Install (not ci) with dependencies, and for Linux vs. Linux Musl (which we use for -alpine)
RUN npm install
# Switch to the node user vs. root
USER node
# Expose port 3000
EXPOSE 3000
# Start the app in debug mode so we can attach the debugger
CMD ["npm", "start"]

## Production ##################################################################
# Also define a production target which doesn't use devDeps
FROM base as production
WORKDIR /home/node/app
COPY --chown=node:node --from=development /home/node/app/node_modules /home/node/app/node_modules
# Build the Docusaurus app
# Use Node.js as the base image for building the application
FROM node:16 AS builder

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install dependencies using npm ci for a deterministic build
RUN npm ci

# Copy the rest of the project files to the working directory
COPY . .

# Build the Docusaurus application
RUN npm run build
CMD ["npm", "run", "serve_prod"]

## Deploy ######################################################################
# Use a stable nginx image
FROM nginx:stable-alpine as deploy
WORKDIR /home/node/app
# Copy what we've installed/built from production
COPY --chown=node:node --from=production /home/node/app/build /usr/share/nginx/html/

# Use Nginx as the base image for the production stage
FROM nginx:alpine

# Copy the built files from the previous stage to the Nginx html directory
COPY --from=builder /app/build /usr/share/nginx/html

# Expose port 80 to allow incoming HTTP traffic
EXPOSE 80

# Run Nginx in the foreground when the container starts
CMD ["nginx", "-g", "daemon off;"]

0 comments on commit 23dd45d

Please sign in to comment.