This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
132 lines (123 loc) · 4.28 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
ARG OSM_COMMIT_SHA=99a7d21a9bc50cdb38559dd0a8b60bc60072b5a1
FROM docker.io/ruby:3.3.0-slim-bookworm as openstreetmap-repo
RUN set -ex \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install \
-y --no-install-recommends \
"curl" \
"unzip" \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /openstreetmap-website
ARG OSM_COMMIT_SHA
RUN curl -L \
"https://github.com/openstreetmap/openstreetmap-website/archive/${OSM_COMMIT_SHA}.zip" \
--output website.zip \
&& unzip website.zip \
&& mv openstreetmap-website-$OSM_COMMIT_SHA/* /openstreetmap-website/ \
&& rm website.zip
FROM docker.io/ruby:3.3.0-slim-bookworm as build
ENV RAILS_ENV=production
ENV DEBIAN_FRONTEND=noninteractive
RUN set -ex \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install \
-y --no-install-recommends \
"build-essential" \
"software-properties-common" \
"locales" \
"tzdata" \
"postgresql-client" \
"nodejs" \
"npm" \
"curl" \
"default-jre-headless" \
"file" \
"git-core" \
"gpg-agent" \
"libarchive-dev" \
"libffi-dev" \
"libgd-dev" \
"libpq-dev" \
"libsasl2-dev" \
"libvips-dev" \
"libxml2-dev" \
"libxslt1-dev" \
"libyaml-dev" \
&& rm -rf /var/lib/apt/lists/* \
&& npm install --global yarn
WORKDIR /app
COPY --from=openstreetmap-repo \
/openstreetmap-website/ /app/
# Install Ruby packages
RUN bundle config set --global path /usr/local/bundle \
&& bundle install \
# Install NodeJS packages using yarn
&& bundle exec bin/yarn install
# A dummy config is required for precompile step below
RUN cp config/example.database.yml config/database.yml \
&& touch config/settings.local.yml \
&& echo "#session key \n\
production: \n\
secret_key_base: $(bundle exec bin/rails secret)" > config/secrets.yml \
# Precompile assets for faster initial load
&& bundle exec bin/rails i18n:js:export assets:precompile
# Package svgo dependency required by image_optim into node single file exe
RUN \
mkdir /bins && cd /bins \
# TODO update this to use node@21 single file executable?
&& npm install -g svgo @yao-pkg/pkg \
&& pkg -t node18-linux /usr/local/bin/svgo
FROM docker.io/ruby:3.3.0-slim-bookworm as runtime
ARG OSM_COMMIT_SHA
ARG GIT_COMMIT
LABEL org.hotosm.osm-sandbox.app-name="osm" \
org.hotosm.osm-sandbox-version="${OSM_COMMIT_SHA}" \
org.hotosm.osm-sandbox-commit-ref="${COMMIT_REF:-none}" \
org.hotosm.osm-sandbox="[email protected]"
ENV RAILS_ENV=production \
PIDFILE=/tmp/pids/server.pid
RUN set -ex \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install \
-y --no-install-recommends \
"locales" \
"tzdata" \
"postgresql-client" \
"curl" \
"libarchive-dev" \
"libffi-dev" \
"libgd-dev" \
"libpq-dev" \
"libsasl2-dev" \
"libvips-dev" \
"libxml2-dev" \
"libxslt1-dev" \
"libyaml-dev" \
# Required image optimisation libraries in OSM prod
"advancecomp" \
"gifsicle" \
"libjpeg-progs" \
"jhead" \
"jpegoptim" \
"optipng" \
"pngcrush" \
"pngquant" \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /app /app
COPY osm-entrypoint.sh /
# Copy svgo requirement as single file executable
COPY --from=build /bins/svgo /usr/local/bin/svgo
RUN \
bundle config set --global path /usr/local/bundle \
# Copy the required config to correct location
# https://github.com/openstreetmap/openstreetmap-website/blob/master/DOCKER.md#initial-setup
&& cp config/example.storage.yml config/storage.yml \
&& cp config/docker.database.yml config/database.yml \
# Replace db --> osm-db compose network service name
&& sed -i 's/host: db/host: osm-db/' config/database.yml \
&& touch config/settings.local.yml \
&& chmod +x /osm-entrypoint.sh
ENTRYPOINT ["/osm-entrypoint.sh"]
CMD ["bundle", "exec", "rails", "s", "-p", "3000", "-b", "0.0.0.0"]