Skip to content

Commit cc01436

Browse files
depsirSleeplessByte
authored andcommitted
Add dockerfile for automated mentoring support (#12)
Fixes #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
1 parent a00c0f8 commit cc01436

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test
2+
dist
3+
node_modules
4+
.git

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM node:lts-alpine as builder
2+
3+
# Install SSL ca certificates
4+
RUN apk update && apk add ca-certificates
5+
6+
# Create appuser
7+
RUN adduser -D -g '' appuser
8+
9+
# get the source code
10+
WORKDIR /javascript-analyzer
11+
COPY . .
12+
13+
# build
14+
RUN yarn install && yarn build && yarn install --prod
15+
16+
# Build a minimal and secured container
17+
FROM node:lts-alpine
18+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
19+
COPY --from=builder /etc/passwd /etc/passwd
20+
COPY --from=builder /javascript-analyzer/bin /opt/analyzer/bin
21+
COPY --from=builder /javascript-analyzer/dist /opt/analyzer/dist
22+
COPY --from=builder /javascript-analyzer/node_modules /opt/analyzer/node_modules
23+
USER appuser
24+
WORKDIR /opt/analyzer
25+
ENTRYPOINT ["/opt/analyzer/bin/analyze.sh"]

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,23 @@ Or directly via the provided shell script:
2727
```
2828

2929
Add the `--debug` and `--console` flags to get output in the terminal window.
30+
31+
## Usage with docker
32+
33+
To create the image, execute the following command from the repository root:
34+
35+
```bash
36+
docker build -t exercism/javascript-analyzer .
37+
```
38+
39+
To `run` from docker pass in the solutions path as a volume and execute with the necessary parameters:
40+
41+
```bash
42+
docker run -v $(PATH_TO_SOLUTION):/solution exercism/javascript-analyzer ${SLUG} /solution
43+
```
44+
45+
Example:
46+
47+
```bash
48+
docker run -v ~/solution-238382y7sds7fsadfasj23j:/solution exercism/javascript-analyzer two-fer /solution
49+
```

bin/analyze.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
# Usage:
44
# ./bin/analyze.sh two_fer ~/test/

0 commit comments

Comments
 (0)