-
-
Notifications
You must be signed in to change notification settings - Fork 362
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
Slim down the Docker images #195
Slim down the Docker images #195
Conversation
@omBratteng is attempting to deploy a commit to a Personal Account owned by @electerious on Vercel. @electerious first needs to authorize it. |
@electerious another thing I might open a PR on, depends if you're interested, is a hardened Docker image. Kinda like I've done here https://github.com/omBratteng/social.hashweb.org/blob/develop/Dockerfile#21 Uses a distroless base image, to reduce possible attack surface |
Seeing as Ackee itself, awaits for being able to connect to the MongoDB, is the |
Thanks for taking a closer look at the dockerfile!
👍
I guess this won't work. The build uses environment variables which can be changed by the user. E.g.
The connection function is async, but it doesn't wait and throws an error when MongoDB isn't available. |
Well, not Ackee, but mongoose, has a 30s timeout on trying to connect. Starting server without a mongodb
Starting docker without mongodb
The only benefit of |
Could change CMD to be Or wise versa, leave it as-is. And add documentation that you can tell docker to run I have created my own hardened image for Ackee, as it's running distroless-nodejs base image. (more information). And my docker-compose.yml Detailsversion: '3.8'
networks:
analytics:
ipam:
config:
- subnet: 172.32.0.0/29
traefik:
external: true
services:
ackee:
image: ghcr.io/bratteng/ackee
container_name: ackee
restart: unless-stopped
runtime: runsc
depends_on:
- mongo
labels:
- traefik.enable=true
- traefik.http.routers.analytics.rule=Host(`analytics.example.com`)
- traefik.http.routers.analytics.entrypoints=https
- traefik.http.routers.analytics.middlewares=secureHeaders@file,analyticsCORS@file
- traefik.http.routers.analytics.tls=true
- traefik.http.routers.analytics.tls.certresolver=letsencrypt
environment:
- ACKEE_USERNAME
- ACKEE_PASSWORD
- ACKEE_MONGODB
networks:
traefik:
analytics:
ipv4_address: 172.32.0.3
dns:
- 8.8.8.8
tty: false
read_only: true
security_opt:
- "no-new-privileges"
mongo:
image: mongo:4.4
container_name: mongo
restart: unless-stopped
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongo 127.0.0.1:27017/test --quiet
interval: 10s
timeout: 10s
runtime: runsc
volumes:
- ./data:/data/db
networks:
analytics:
ipv4_address: 172.32.0.2 |
That's cool. I wasn't aware that there's a timeout. We should change the
I know that it's not perfect to wait until it's compiled, but I want to keep it simple. Users should be able to start the image without accidentally getting old files. An automatic alternative: We could check if |
To run the application, we only need `package.json`, `yarn.lock`, `build.js` and `src/`
The user can on their side tell Docker to run `yarn server` if they're happy with the default files
I have bumped
Reverted it back to run the
I actually was thinking about that, by using an entrypoint file, that checks for the env variables, and then determines if it should run build or start it directly. But that could be in another PR |
Perfect 🙌 I've learned a few new things about Docker thanks to this PR. I've also realised that we can install dependencies with |
Install with production dependencies only
The Docker image is now around 58% smaller 😎 |
This changes to a multi-stage build, and To run the application, we only need
package.json
,yarn.lock
,build.js
,node_modules
andsrc/
Changes done
Reduces the docker image with 193MB