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

Add Docker #164

Closed
jgroom33 opened this issue Sep 25, 2019 · 14 comments
Closed

Add Docker #164

jgroom33 opened this issue Sep 25, 2019 · 14 comments
Labels
feature New feature or request

Comments

@jgroom33
Copy link
Contributor

it would be nice to have no install dependencies except docker.

expected behavior: docker run -it -p 3000:3000 liyasthomas/postwoman:latest

@jgroom33
Copy link
Contributor Author

@liyasthomas
“Set up Automated Builds using GitHub and Docker Hub” by oleksii_y https://link.medium.com/AmD5s8x6f0

@liyasthomas
Copy link
Member

We're already making use of Travis CI for deployments. And I'm not experienced with docker. Would you care to explain docker CD advantages over other CIs?

@liyasthomas liyasthomas added feature New feature or request need information Requires more info labels Sep 25, 2019
@jgroom33
Copy link
Contributor Author

the requirement is:
Publish an image to docker hub liyasthomas/postwoman

This account needs to exist so the image can be published there.

Then the image needs to be pushed there.

It's probably possible to do this with Travis, but it would require that to be setup in Travis. (Ie add a token for docker hub in Travis)

If docker hub is used, the process is easier. Just link your GitHub account from docker hub and it will watch for new releases. When a new release is published, it builds the image using the docker file and publishes it.

@liyasthomas
Copy link
Member

Cool! Let me do a background check on it and will let you know.

@liyasthomas
Copy link
Member

Closed by accident

@liyasthomas
Copy link
Member

liyasthomas commented Sep 26, 2019

@jgroom33
https://hub.docker.com/r/liyasthomas/postwoman
docker pull liyasthomas/postwoman

@liyasthomas liyasthomas removed the need information Requires more info label Sep 26, 2019
@jgroom33
Copy link
Contributor Author

Works great. Now just need to update the readme with:
docker run -p 3000:3000 liyasthomas/postwoman:latest

@liyasthomas
Copy link
Member

Will do

@liyasthomas
Copy link
Member

@jgroom33 can you tell me why docker taking ~12 mins to build? Any optimizations you wanna suggest to dockerfile?

@jgroom33
Copy link
Contributor Author

Where are you seeing the 12 minutes?
One of the things that would be good is to use an alpine image. They are much smaller (50M compared to 300M)
But that would only impact time if the root image is being downloaded each build.
I tried to use an alpine image originally, but the build failed.

@liyasthomas
Copy link
Member

Build duration was 12 mins.
Let me see if I could build with alpine rather than buster.

@jgroom33
Copy link
Contributor Author

jamesgeorge007 referenced this issue in jamesgeorge007/hoppscotch Sep 29, 2019
@jls-tschanzc
Copy link

Another improvement might be to use tini and switching from "npm run start" to directly executing the nuxt command. Just add "tini" to the apk add command and then switch the CMD line with:

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["nuxt", "start"]

Another nice to have feature might be a healthcheck, something like this:

HEALTHCHECK --interval=5m --timeout=3s CMD curl --fail http://localhost:3000/health || exit 1

I am not entirely sure how nuxt works and what dependencies it needs for runtime but maybe it could further slim down the resulting image by using a multi stage build so you would prepare everything for the npm run build in the first stage and run the build and then in the second stage you would only copy over the resulting build artefacts and set ENV NODE_ENV production as well as run only npm install --only=prod (IF all the dependencies are even required for nuxt to run).

@pidario
Copy link

pidario commented Jan 13, 2020

Sorry to comment under a closed issue, but in response to the previous comment I tried this Dockerfile:

FROM node:12.10.0-alpine as builder

WORKDIR /app

# Add git as the prebuild target requires it to parse version information
RUN apk add --update --no-cache \
  git \
  tini \
  ca-certificates

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build
######################################################################################
FROM node:12.10.0-alpine as runner

LABEL maintainer="Liyas Thomas (liyascthomas@gmail.com)"

COPY --from=builder /sbin/tini /sbin/tini
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

WORKDIR /app

COPY --from=builder /app .

EXPOSE 3000

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node_modules/.bin/nuxt", "start"]

I added tini as suggested and I also took the liberty to add ca-certificates.

I usually build this Dockerfile by using two different commands in sequence:
docker build --target builder -t builder-postwoman:latest .
This image is used for caching purposes only and is not pushed to docker hub: note the tag is just builder-postwoman;
and then
docker build --target runner -t liyasthomas/postwoman:latest .
This one instead has the usual tag you currently use and will be pushed to DH.

The image got shrunk down to 303MB, which is not bad for a nodejs application this large but probably you could still improve it by installing production dependencies only (for example you don't need test suite in production) as suggested by @jls-tschanzc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants