Skip to content

Commit 2b3b3c9

Browse files
OP#55 Update Docker Process to Build App (#110)
2 parents bdb3fca + 2646b97 commit 2b3b3c9

File tree

7 files changed

+4137
-4397
lines changed

7 files changed

+4137
-4397
lines changed

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
docs/
2+
.github/
3+
.gitignore
4+
.dockerignore
5+
Dockerfile
6+
Makefile
7+
LICENSE
8+
README.md
9+
eslint.config.mjs

.github/workflows/docker-deploy.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,26 @@ jobs:
2323
steps:
2424
- name: Checkout repository
2525
uses: actions/checkout@v4
26-
- name: Build React App
27-
env: # If using this frontend for your own usecase change this backend url to your backend url
28-
REACT_APP_BACKEND_SERVER: "https://api.labconnect.cs.rpi.edu"
29-
run: |
30-
npm ci --legacy-peer-deps
31-
CI=false
32-
npm run build
26+
3327
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
3428
- name: Log in to the Container registry
3529
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
3630
with:
3731
registry: ${{ env.REGISTRY }}
3832
username: ${{ github.actor }}
3933
password: ${{ secrets.GITHUB_TOKEN }}
40-
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
34+
35+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
4136
- name: Extract metadata (tags, labels) for Docker
4237
id: meta
4338
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
4439
with:
4540
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
46-
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
41+
tags: |
42+
type=ref,event=branch,pattern=main
43+
type=raw,value=latest
44+
45+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
4746
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
4847
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
4948
- name: Build and push Docker image

.github/workflows/docker-test.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,32 @@ on:
99
- "**.tsx"
1010
- "package.json"
1111
- "package-lock.json"
12+
- "Dockerfile"
13+
- ".dockerignore"
1214

1315
jobs:
1416
build:
1517
runs-on: ubuntu-latest
1618
steps:
1719
- uses: actions/checkout@v4
1820

19-
- name: Build React App
20-
run: |
21-
npm ci --legacy-peer-deps
22-
CI=false
23-
REACT_APP_BACKEND_SERVER="https://api.labconnect.cs.rpi.edu"
24-
npm run build
25-
2621
- name: "Build Docker Image"
2722
run: |
2823
docker build -t labconnect-frontend .
2924
3025
- name: "Run Docker Container"
3126
run: |
3227
docker run -d --name labconnect-frontend-container labconnect-frontend
33-
sleep 60
28+
sleep 30
3429
docker logs labconnect-frontend-container
3530
docker stop labconnect-frontend-container
31+
32+
- name: "Check for Container Exit Code"
33+
id: check_exit_code
34+
run: |
35+
docker inspect labconnect-frontend-container --format='{{.State.ExitCode}}'
3636
docker rm labconnect-frontend-container
37+
38+
- name: "Fail if Container Fails"
39+
if: steps.check_exit_code.outputs.exit_code != '0'
40+
run: exit 1

.github/workflows/eslint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
node-version: 22
1919

2020
- name: Install dependencies
21-
run: npm ci --legacy-peer-deps
21+
run: npm ci
2222

2323
- name: Run EsLint
2424
uses: sibiraj-s/action-eslint@v3

Dockerfile

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1-
FROM --platform=linux/amd64 node:22.9.0-alpine3.20
1+
FROM node:23-alpine3.21 AS base
2+
3+
# Install dependencies
4+
FROM base AS deps
5+
6+
WORKDIR /app
7+
8+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
9+
RUN apk add --no-cache libc6-compat
10+
11+
COPY package.json package-lock.json ./
12+
13+
RUN npm ci
14+
15+
# Build the app with the node modules installed
16+
FROM base AS builder
17+
18+
WORKDIR /app
19+
20+
COPY --from=deps /app/node_modules ./node_modules
21+
COPY . .
22+
23+
RUN npm run build
24+
25+
# Create a new image with the build files
26+
FROM base AS runner
227

328
WORKDIR /app
429

5-
COPY build /app/build
30+
COPY --from=builder /app/build ./build
631
RUN npm install -g serve
732

833
HEALTHCHECK --interval=10s --timeout=5s --start-period=5s --retries=3 \

0 commit comments

Comments
 (0)