-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
148 lines (116 loc) · 4.74 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#
# This Dockerfile is for DEVELOPMENT and TESTING purposes ONLY it is not suitable for production use, its huge and has a lot of unnecessary packages!
#
# If you don't have an M* mac you probably don't need to use this but it might make setting things up a little easier for you
#
# If you need to leave the container running for example to debug something you can use the following command to keep it running
# CMD ["tail", "-f", "/dev/null"]
# if your using these values anywhere new see https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
# we don't set any defaults here on purpose as we will mostly use this as a development environment not setting an env value lets us run tests in the container easily
ARG NODE_ENV=development
ARG RAILS_ENV=development
# ----------------------------------------------------------------
FROM ghcr.io/wearefuturegov/outpost-dev-base:latest as install
# make this stage non-interactive
ENV DEBIAN_FRONTEND=noninteractive
# Switch back to the root user for a second to install some packages
USER root
RUN apt-get update --error-on=any
# for pg gem
RUN apt-get install -y \
libpq-dev \
postgresql
# for chrome for tests
RUN apt-get install -y \
gconf-service \
libappindicator1 \
libasound2 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcairo-gobject2 \
libdrm2 \
libgbm1 \
libgconf-2-4 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libx11-xcb1 \
libxcb-dri3-0 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxfixes3 \
libxi6 \
libxinerama1 \
libxrandr2 \
libxshmfence1 \
libxss1 \
libxtst6 \
fonts-liberation \
jq
# Fetch the latest version numbers and URLs for Chrome and ChromeDriver
RUN curl -s https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json > /tmp/versions.json
# chrome
RUN CHROME_URL=$(jq -r '.channels.Stable.downloads.chrome[] | select(.platform=="linux64") | .url' /tmp/versions.json) && \
wget -q --continue -O /tmp/chrome-linux64.zip $CHROME_URL && \
unzip -j -o /tmp/chrome-linux64.zip -d /opt/chrome
RUN chmod +x /opt/chrome/chrome
# chromedriver
RUN CHROMEDRIVER_URL=$(jq -r '.channels.Stable.downloads.chromedriver[] | select(.platform=="linux64") | .url' /tmp/versions.json) && \
wget -q --continue -O /tmp/chromedriver-linux64.zip $CHROMEDRIVER_URL && \
unzip -j -o /tmp/chromedriver-linux64.zip -d /opt/chromedriver && \
chmod +x /opt/chromedriver/chromedriver
# Clean up
RUN rm /tmp/chrome-linux64.zip /tmp/chromedriver-linux64.zip /tmp/versions.json
ENV PATH /opt/chrome:/opt/chromedriver:$PATH
RUN echo 'export PATH="/opt/chrome:/opt/chromedriver:$PATH"' >> ~/.bashrc
# Check chrome & chromedriver versions
RUN echo "Chrome: " && chrome --version
RUN echo "Chromedriver: " && chromedriver --version
RUN chown -R outpost-user:outpost-user /home/outpost-user/.cache
USER outpost-user
# set $HOME to outpost-user path for this non-interactive session
ENV HOME /home/outpost-user
ENV PATH $HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH
WORKDIR /app
COPY --chown=outpost-user:outpost-user ./.ruby-version ./.ruby-version
COPY --chown=outpost-user:outpost-user ./Gemfile ./Gemfile
COPY --chown=outpost-user:outpost-user ./Gemfile.lock ./Gemfile.lock
COPY --chown=outpost-user:outpost-user ./package.json ./package.json
COPY --chown=outpost-user:outpost-user ./yarn.lock ./yarn.lock
COPY --chown=outpost-user:outpost-user ./.docker/bin/check-versions.sh ./.docker/bin/check-versions.sh
RUN ls -lah
RUN pwd
# check everything is all good
RUN ./.docker/bin/check-versions.sh
# set the environment variables
ARG NODE_ENV
ARG RAILS_ENV
ENV NODE_ENV=${NODE_ENV}
ENV RAILS_ENV=${RAILS_ENV}
# -------------
# install gems
# -------------
# throw errors if Gemfile has been modified since Gemfile.lock
RUN if [ "${RAILS_ENV}" = "production" ]; then \
bundle config --global frozen 1; fi
RUN if [ "${RAILS_ENV}" = "development" ] || [ -z "${RAILS_ENV}" ]; then \
bundle install --verbose; fi
RUN if [ "${RAILS_ENV}" = "production" ]; then \
bundle config set --local deployment 'true' && bundle install; fi
# -------------
# install node modules
# -------------
RUN if [ "${NODE_ENV}" = "development" ] || [ -z "${NODE_ENV}" ]; then \
yarn install; fi
RUN if [ "${NODE_ENV}" = "production" ]; then \
yarn install --frozen-lockfile; fi
RUN if [ "${APP_ENV}" = "production" ]; then \
NODE_OPTIONS=--openssl-legacy-provider SECRET_KEY_BASE=dummyvalue bundle exec rails assets:precompile; fi
# after this point we don't need to be non-interactive anymore since we'll be running the container
ENV DEBIAN_FRONTEND=
EXPOSE 3000
ENTRYPOINT [".docker/dev-docker-entrypoint.sh"]
CMD ["bin/rails", "s", "-u", "puma", "-p", "3000", "-b=0.0.0.0"]
# CMD ["bin/bundle", "exec", "puma", "-C", "config/puma.rb"]
# CMD ["tail", "-f", "/dev/null"]