Skip to content
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

feat: Optimize Docker image, build for amd64+arm64 #173

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
# Default ignored files
.env
.idea
node_modules/
renovate.json
.github
README.md
**/.DS_Store
**/.env
**/node_modules

.gitignore
.gitattributes
.github
.idea
.vscode

README.md
CHANGELOG.md

renovate.json
.release-please-manifest.json
release-please-config.json

.dockerignore
Dockerfile

# build folders and files
/dist
**/dist
.nyc_output
/tmp
/coverage
/junit.xml

# test folders and files
/test
/integration
/backend/test

# configuration
/config
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: ./
platforms: linux/amd64,linux/arm64
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
20 changes: 14 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,31 @@ WORKDIR /app
COPY package*.json ./
COPY backend/package*.json ./backend/
COPY frontend/package*.json ./frontend/
RUN npm ci
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#node-gyp-alpine
RUN apk add --no-cache --virtual .gyp python3 py-setuptools make g++ \
&& npm ci \
&& apk del .gyp

# copy in app code and build it
COPY . .
RUN npm run build


# -- execution --
FROM node:20.18.1-alpine
WORKDIR /app

# install PRODUCTION dependencies
RUN apk add --no-cache tini

# install production dependencies
COPY package*.json ./
COPY backend/package*.json ./backend/
COPY frontend/package*.json ./frontend/
RUN npm ci --omit=dev
RUN apk add --no-cache tini

# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#node-gyp-alpine
RUN apk add --no-cache --virtual .gyp python3 py-setuptools make g++ \
&& npm ci --omit=dev --workspace=backend --include-workspace-root \
&& npm cache clean --force \
&& apk del .gyp

# add the already compiled code and the default config
# (custom config must be set via volume)
Expand All @@ -37,4 +45,4 @@ EXPOSE 8080

# use tini as init process since Node.js isn't designed to be run as PID 1
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "--disable-proto=delete", "dist/main.js"]
CMD ["node", "--enable-source-maps", "--disable-proto=delete", "dist/main.js"]
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ For more information, refer to the [Kubernetes RBAC documentation](https://kuber

### Docker

You can run Foreman via Docker using the following command:
You can run Foreman via Docker:

```sh
docker run -p 8080:8080 -v /path/to/config:/app/config contane/foreman:latest
docker run --detach \
--restart=unless-stopped \
--cap-drop=all \
--security-opt=no-new-privileges \
--read-only \
--volume=/path/to/config:/app/config:ro \
-p=8080:8080/tcp \
contane/foreman:latest
```

Here, `/path/to/config` is the path to the configuration directory on the host, and Foreman will be accessible on
Expand Down
1 change: 1 addition & 0 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"inlineSourceMap": true,
"outDir": "./dist"
},
"include": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test": "npm run test:unit && npm run test:integration",
"test:unit": "npm run test --workspaces --if-present && mocha --require tsx --recursive \"test/**/*.ts\"",
"test:integration": "mocha --require tsx --recursive \"integration/**/*.ts\"",
"start": "node --disable-proto=delete dist/main.js"
"start": "node --enable-source-maps --disable-proto=delete dist/main.js"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": false,
"inlineSourceMap": true,
"outDir": "./dist"
},
"include": [
Expand Down