forked from orcasound/orcasite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
79 lines (58 loc) · 2.35 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Largely based on https://github.com/nicbet/docker-phoenix/blob/main/Dockerfile
FROM node:22.8.0-alpine@sha256:bec0ea49c2333c429b62e74e91f8ba1201b060110745c3a12ff957cd51b363c6 AS node
FROM elixir:1.16-otp-26-alpine@sha256:829bebfcdc6fc58c56effc0d77f660de7c902fcf74e785b3175ee3a8f739b3f5 AS setup
### Install deps
RUN apk --no-cache --update add \
# General deps
bash git curl rsync \
# Elixir
inotify-tools build-base \
# NPM
python3
# Workaround for getting picosat_elixir to compile on alpine
# https://stackoverflow.com/questions/52894632/cannot-install-pycosat-on-alpine-during-dockerizing
RUN echo "#include <unistd.h>" > /usr/include/sys/unistd.h
RUN mix local.hex --force && \
mix local.rebar --force
### Install node
# "borrow" the node install from the official node alpine image so that we don't
# have to do all the messy compilation (due to being on musl)
# Inspired by https://github.com/beardedeagle/alpine-phoenix-builder/blob/16695c570ce55a86f01b7e45cabbd23848cf48e3/Dockerfile#L34
# and https://stackoverflow.com/a/76132347
COPY --from=node /usr/local /opt/node
# Use rsync to merge in the node files into /usr/local without overwriting
# everything already in there, then clean up
RUN rsync -a /opt/node/ /usr/local && \
rm -rf /opt/node
# Install global npm packages
RUN npm install -g yarn --force
### Container setup
ENV APP_HOME /app
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME
ARG MIX_ENV=dev
EXPOSE 3000
EXPOSE 4000
ENV PORT=4000 UI_PORT=3000 MIX_ENV=${MIX_ENV}
# Create a new stage for local dev docker-compose to stop at (using target: setup)
# Local dev is configured to mount local files into the container so there's no
# point in adding/compiling deps as part of the docker build process
FROM setup AS compile
### Install dependencies and compile
# Download and compile server deps
ADD server/mix.exs server/mix.lock server/
ADD server/config server/config/
RUN cd server && mix do deps.get, deps.compile
# Download and install UI deps
ADD ui/package.json ui/package-lock.json ui/
RUN cd ui && npm install
# Compile server code
ADD server server/
RUN cd server && mix compile
RUN cd server && mix do tailwind.install, esbuild.install
# Compile UI code
ADD ui ui/
RUN cd ui && npm run build:dev
# Copy remaining files
ADD . .
CMD ["/bin/bash", "-c", "cd server && mix ecto.setup && mix phx.server & cd ui && npm run start:dev"]