-
Notifications
You must be signed in to change notification settings - Fork 52
/
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.9.0-alpine@sha256:c9bb43423a6229aeddf3d16ae6aaa0ff71a0b2951ce18ec8fedb6f5d766cf286 AS node
FROM elixir:1.17-otp-27-alpine@sha256:a1428b2bf7c25dcea1f40fec1991dc931c4307235a279f1c71d315586bd8297c 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"]