Skip to content

Commit 195e853

Browse files
mikehelmickknative-prow-robot
authored andcommitted
Update the serving Elixir example to freeze to 1.6 and to be compatible with Google Cloud Build (#461)
* Add an elixir language sample using the phoenix framework to the knative serving samples. * Add links to Elixir and Phoenix Web sites. * remove giant package-lock.json * change -go to -elixir in readme. * Update the Elixir example so that it builds with Google's Cloud Build service. Add an approprite .gcloudignore file so that this can be done using the gcloud command line tool.
1 parent d1b78c4 commit 195e853

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# For building with Google Cloud Build using the gcloud command line tool.
2+
# Similar to .gitignore, except we want the /config/*.secrete.exs uploaded for the build.
3+
4+
# App artifacts
5+
/_build
6+
/db
7+
/deps
8+
/*.ez
9+
10+
# Generated on crash by the VM
11+
erl_crash.dump
12+
13+
# Generated on crash by NPM
14+
npm-debug.log
15+
/assets/package-lock.json
16+
17+
# Static artifacts
18+
/assets/node_modules
19+
20+
# Since we are building assets from assets/,
21+
# we ignore priv/static. You may want to comment
22+
# this depending on your deployment strategy.
23+
/priv/static/
24+

serving/samples/helloworld-elixir/Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM elixir:alpine
1+
FROM elixir:1.6.6-alpine
2+
23
ARG APP_NAME=hello
34
ARG PHOENIX_SUBDIR=.
45
ENV MIX_ENV=prod REPLACE_OS_VARS=true TERM=xterm
@@ -8,6 +9,7 @@ RUN apk update \
89
&& mix local.rebar --force \
910
&& mix local.hex --force
1011
COPY . .
12+
1113
RUN mix do deps.get, deps.compile, compile
1214
RUN cd ${PHOENIX_SUBDIR}/assets \
1315
&& npm install \
@@ -17,8 +19,18 @@ RUN cd ${PHOENIX_SUBDIR}/assets \
1719
RUN mix release --env=prod --verbose \
1820
&& mv _build/prod/rel/${APP_NAME} /opt/release \
1921
&& mv /opt/release/bin/${APP_NAME} /opt/release/bin/start_server
22+
2023
FROM alpine:latest
2124
RUN apk update && apk --no-cache --update add bash openssl-dev
25+
26+
RUN addgroup -g 1000 appuser && \
27+
adduser -S -u 1000 -G appuser appuser
28+
29+
RUN mkdir -p /opt/app/var
30+
RUN chown appuser /opt/app/var
31+
32+
USER appuser
33+
2234
ENV PORT=8080 MIX_ENV=prod REPLACE_OS_VARS=true
2335
WORKDIR /opt/app
2436
EXPOSE 8080

serving/samples/helloworld-elixir/README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@ Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
3838

3939
```docker
4040
# Start from a base image for elixir
41-
FROM elixir:alpine
41+
# Phoenix works best on pre 1.7 at the moment.
42+
FROM elixir:1.6.6-alpine
4243
4344
# Set up Elixir and Phoenix
4445
ARG APP_NAME=hello
4546
ARG PHOENIX_SUBDIR=.
4647
ENV MIX_ENV=prod REPLACE_OS_VARS=true TERM=xterm
4748
WORKDIR /opt/app
4849
49-
# Compile assets.
50+
# Update nodejs, rebar, and hex.
5051
RUN apk update \
5152
&& apk --no-cache --update add nodejs nodejs-npm \
5253
&& mix local.rebar --force \
@@ -69,10 +70,19 @@ Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
6970
# Prepare final layer
7071
FROM alpine:latest
7172
RUN apk update && apk --no-cache --update add bash openssl-dev
72-
ENV PORT=8080 MIX_ENV=prod REPLACE_OS_VARS=true
73-
WORKDIR /opt/app
73+
74+
# Add a user so the server will run as a non-root user.
75+
RUN addgroup -g 1000 appuser && \
76+
adduser -S -u 1000 -G appuser appuser
77+
# Pre-create necessary temp directory for erlang and set permissions.
78+
RUN mkdir -p /opt/app/var
79+
RUN chown appuser /opt/app/var
80+
# Run everything else as 'appuser'
81+
USER appuser
7482
7583
# Document that the service listens on port 8080.
84+
ENV PORT=8080 MIX_ENV=prod REPLACE_OS_VARS=true
85+
WORKDIR /opt/app
7686
EXPOSE 8080
7787
COPY --from=0 /opt/release .
7888
ENV RUNNER_LOG_DIR /var/log

0 commit comments

Comments
 (0)