-
Notifications
You must be signed in to change notification settings - Fork 0
Docker deployment setup #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ramonechen
wants to merge
13
commits into
main-preview
Choose a base branch
from
deployment-setup
base: main-preview
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
159ab46
Merge pull request #127 from Project-CARPI/main-preview
mirmirmirr 99ef592
Use inclusion pattern in .dockerignore
ramonechen 1d789af
Add clarifying comments to Dockerfile
ramonechen 87344f4
Ensure npm uses 11.12.x in Dockerfile
ramonechen 662c0af
Clean Compose file
ramonechen c5086be
Create image-publish.yml
ramonechen 54a97ad
Restrict image-publish.yml to merges with main
ramonechen 66508fa
Add top-level comment to Compose file
ramonechen c940650
Fix incorrect comment in Compose file
ramonechen 3704b91
Repurpose Dockerfile for production
ramonechen 694f60e
Override production command in Compose for development
ramonechen cb3fceb
Use two-stage builds in Dockerfile
ramonechen 75dd4eb
Use NGINX instead of serve for production
ramonechen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,18 @@ | ||
| node_modules | ||
| dist | ||
| build | ||
| .git | ||
| .env | ||
| docker-compose.yml | ||
| Dockerfile | ||
| # Ignore all files | ||
|
|
||
| * | ||
|
|
||
| # Whitelist necessary build and config files from project root | ||
| !eslint.config.js | ||
| !index.html | ||
| !package-lock.json | ||
| !package.json | ||
| !tsconfig.app.json | ||
| !tsconfig.json | ||
| !tsconfig.node.json | ||
| !vite.config.ts | ||
| !nginx.conf | ||
|
|
||
| # Whitelist source and public directories | ||
| !public/ | ||
| !src/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| name: Build and Push Docker Image to GHCR | ||
|
|
||
| # Run this workflow every time code is pushed or merged to the main branch | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| call-build-and-push: | ||
| uses: project-carpi/.github/.github/workflows/image-publish.yml@main | ||
|
ramonechen marked this conversation as resolved.
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| secrets: inherit | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,33 @@ | ||
| FROM node:24.14.0-alpine | ||
|
|
||
| WORKDIR /app | ||
| COPY package*.json ./ | ||
| # --- BASE STAGE --- | ||
| FROM node:24.14.0-alpine AS base | ||
| # Update npm to 11.12.x to comply with project's package-lock.json | ||
| RUN npm install -g npm@11.12.0 | ||
| # Store all application files in /site | ||
| WORKDIR /site | ||
| # Copy package.json and package-lock.json to the container | ||
| COPY package*.json . | ||
| # Install dependencies using npm ci for a clean install | ||
| RUN npm ci | ||
| # Copy the rest of the application code to the container | ||
| COPY . . | ||
| EXPOSE 5173 | ||
|
|
||
| # --- DEVELOPMENT STAGE --- | ||
| FROM base AS dev | ||
| EXPOSE 5173 | ||
| # Start the development server | ||
| CMD ["npm", "run", "dev"] | ||
|
|
||
| # --- BUILD STAGE --- | ||
| FROM base AS build | ||
| # Build the application for production | ||
| RUN npm run build | ||
|
|
||
| # --- PRODUCTION STAGE --- | ||
| # Start from a clean NGINX image for production | ||
| FROM nginx:alpine AS prod | ||
| # Copy custom NGINX configuration to serve the built application | ||
| COPY nginx.conf /etc/nginx/conf.d/default.conf | ||
| # Copy the built application from the build stage | ||
| COPY --from=build /site/dist /usr/share/nginx/html | ||
| EXPOSE 80 | ||
| # NGINX starts automatically when the container runs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,40 @@ | ||
| services: | ||
| web: | ||
| build: . | ||
| image: carpi-dev:latest | ||
| # Docker Compose configuration for the CARPI website development environment. | ||
| # | ||
| # To start the development environment, run: | ||
| # docker compose run --rm --service-ports site | ||
| # | ||
| # This will build the Docker image for the site service if it doesn't already | ||
| # exist, and then start the container. An interactive terminal will be attached | ||
| # to the container so Vite commands can be entered. | ||
| # | ||
| # To stop the development environment, use Q+Enter in the terminal. The | ||
| # container will automatically be removed after it stops due to the --rm flag. | ||
| # | ||
| # Alternatively, you can run the container in detached (background) mode with: | ||
| # docker compose up -d | ||
| # | ||
| # To stop the detached container, run: | ||
| # docker compose down | ||
|
|
||
| # expose port 5173 | ||
| ports: | ||
| - "5173:5173" | ||
|
|
||
| # mount the current directory to /app in the container | ||
| volumes: | ||
| - .:/app | ||
| - /app/node_modules | ||
| name: carpi-site-dev-environment | ||
|
|
||
| # interactive terminal | ||
| services: | ||
| site: | ||
| build: | ||
| context: . | ||
| target: dev | ||
| image: carpi-site:latest | ||
| container_name: carpi-site | ||
| # Ensure image is built locally and is not pulled from a registry | ||
| pull_policy: build | ||
| restart: on-failure | ||
| # Enable interactive mode to allow Vite command input and output | ||
| stdin_open: true | ||
| tty: true | ||
| ports: | ||
| - "5173:5173" | ||
| # Mount local code over the code built into the container for automatic | ||
| # reloading during development. | ||
| volumes: | ||
| - .:/site | ||
| - /site/node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| server { | ||
| listen 80; | ||
| server_name localhost; | ||
|
|
||
| location / { | ||
| root /usr/share/nginx/html; | ||
| index index.html index.htm; | ||
| # Fallback to index.html if the path isn't a real file | ||
| try_files $uri $uri/ /index.html; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.