Skip to content

Conversation

@depsir
Copy link
Contributor

@depsir depsir commented May 26, 2019

I created a first draft of dockerfile, inspired by the go-analyzer, having in mind the guidelines of automated-mentoring-support.
This pr is intended to fix #7

Some info about the choices made:

  • node version: lts
  • decided to run the analyzer as an unprivileged user
  • apk update to make the build with the latest dependencies and security fixes
  • two phase build, copying node_modules after yarn install --prod, to keep only runtime needed dependencies
  • Added certificates because it couldn't be bad
  • I changed /bin/bash to /bin/sh in the analyze.sh file since bash is not present in linux-alpine, probably it could be #!/usr/bin/env sh

Copy link
Member

@SleeplessByte SleeplessByte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node version

LTS please 💯

go version had certificates, user and stuff. are they needed for something?

@tehsphinx might have more on that, but in general it is probably a good thing to add a special user (such as deploy or analyzer-user) that will have execution rights to node and whatsnot. The certificates I think is to make sure the certificates are in sync given:

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

should I apk update?

Let's ask @ErikSchierboom and @tehsphinx

the two phase build should help keeping the final image small, so I wanted to copy only bin and dist. I had to copy node_modules too since the shell script needs the module esm. This could be fixed by copying only that module, or by creating an ad hoc package.json just to setup the final image (or we can just keep the build image as final image)

You may vendor package esm. Preferably by:

  • add it to devDependencies and NOT dependencies
  • copy it from node_modules during build / package

I changed /bin/bash to /bin/sh in the analyze.sh file since bash is not present in linux-alpine

Fine with me!

@ErikSchierboom
Copy link
Member

Let's ask @ErikSchierboom

What exactly is the question? (sorry for not understanding)

@NobbZ
Copy link
Member

NobbZ commented May 27, 2019

What exactly is the question? (sorry for not understanding)

I think it is whether one should do an apk update in the containers.

Personally I do not hink its necessary. We can and should assume that FROM alpine:latest produces already a base image that us current (enough), honestly, it contains so little of base packages, that there usually is not much to update…

The index, which was the main reason for doing apk update in the "old days", is nowadays updated inmen when doing apk add --no-cache.

Doing apk update wrong might cause additional diskspace needed by the image.

@SleeplessByte
Copy link
Member

@NobbZ thank you for your elaborate answer and yes @ErikSchierboom what he said was the question!

Dockerfile Outdated

# Create appuser
#RUN adduser -D -g '' appuser && mkdir /go-analyzer
RUN mkdir /javascript-analyzer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the WORKDIR command is used later, the RUN mkdir can be removed - WORKDIR creates the directory if it does not exist

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
Copy link

@ZapAnton ZapAnton May 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the script more cross-platform, perhaps the #!/usr/bin/env sh could be used here?

Copy link
Member

@SleeplessByte SleeplessByte May 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked on my machine, no problems with passing several arguments to the script - $1 and $2 work as intended

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus I am using the #!/usr/bin/env sh in my Docker image, and it works there as well

@@ -0,0 +1,3 @@
test
dist
node_modules

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the git commands are not used in the Dockerfile, it would make sense to add the .git directory here.
This way the Docker cache will not be invalidated when the git commands are run on the developer machine

Dockerfile Outdated
COPY --from=builder /javascript-analyzer/bin /opt/analyzer/bin
COPY --from=builder /javascript-analyzer/dist /opt/analyzer/dist
COPY --from=builder /javascript-analyzer/node_modules /opt/analyzer/node_modules
RUN chmod +x /opt/analyzer/bin/analyze.sh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If storing executable scripts is OK for you, the chmod could be run on the repository file.
Docker saves the file permissions when they are copied.
Then this line can be removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed @depsir . This was fixed (#1)

Dockerfile Outdated
WORKDIR /javascript-analyzer

# get the rest of the source code
COPY . /javascript-analyzer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to the COPY . .. You are already in the javascript-analyzer directory, because of the previous WORKDIR command.

@tehsphinx
Copy link
Member

About the certificates and the user:
I'm not a docker security expert but every time I see some example about a secure Go container from scratch it creates a user and adds certificates. So basically it is about running as a pretty much unprivileged user.

@tehsphinx
Copy link
Member

tehsphinx commented May 27, 2019

About apk update: Probably both is fine:

  • Doing apk update AND using a 2 step build for the container (then it does not affect image size)
  • Leaving apk update out

Again: security. If we leave it out the builds are dependent on the underlying container to bring in security updates regularly.

@SleeplessByte
Copy link
Member

I personally prefer to do the apk update then, @depsir

@ErikSchierboom
Copy link
Member

Regarding the apk update, I'm generally in favor of updating all dependencies where possible.

@SleeplessByte
Copy link
Member

About the certificates and the user:
I'm not a docker security expert but every time I see some example about a secure Go container from scratch it creates a user and adds certificates. So basically it is about running as a pretty much unprivileged user.

@depsir per this, can we also add the certificates :) ?

@depsir depsir changed the title [WIP] Add dockerfile for automated mentoring support Add dockerfile for automated mentoring support May 29, 2019
Copy link
Member

@SleeplessByte SleeplessByte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added suggestion inline which I'll apply -- let's see if this flies. Amazing work @depsir 🚀 🚀 🚀

@SleeplessByte SleeplessByte merged commit cc01436 into exercism:master May 30, 2019
SleeplessByte added a commit to exercism/typescript-analyzer that referenced this pull request Jun 4, 2019
* Create CODE_OF_CONDUCT (originally @SleeplessByte exercism/javascript-analyzer#5)

* Add dockerfile for automated mentoring support (originally @depsir exercism/javascript-analyzer#12)

* Initial smoke for usage of jest (originally: @SleeplessByte exercism/javascript-analyzer#17)

* Apply design and proper interface and structure (originally: @SleeplessByte exercism/javascript-analyzer#18)

* Fixes issues in the README.md (originally: @zeckdude exercism/javascript-analyzer#19)
SleeplessByte added a commit to exercism/typescript-analyzer that referenced this pull request Jun 4, 2019
* Create CODE_OF_CONDUCT (originally @SleeplessByte exercism/javascript-analyzer#5)

* Add dockerfile for automated mentoring support (originally @depsir exercism/javascript-analyzer#12)

* Initial smoke for usage of jest (originally: @SleeplessByte exercism/javascript-analyzer#17)

* Apply design and proper interface and structure (originally: @SleeplessByte exercism/javascript-analyzer#18)

* Fixes issues in the README.md (originally: @zeckdude exercism/javascript-analyzer#19)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Dockerfile

7 participants