-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
78 lines (56 loc) · 2.26 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
# Compiling our frontend assets
# Since we only need need Node for generating our bundle
# we will use a multi-stage build to keep our image small
# setting up our image aliased as build
FROM node:12.2.0-alpine as build
# set working directory inside node
WORKDIR /usr/src/node_app
# environment vars must be included in dockerfile
ARG NODE_ENV=production
# Add our node modules to our path
ENV PATH /usr/src/node_app/node_modules/.bin:$PATH
# copy over our package.json
COPY package.json /usr/src/node_app/package.json
# install dependencies silently so we don't have to
# watch the whole thing download every time
RUN npm install --silent
# Copy over the rest of our file so webpack will be able bundle it
COPY . /usr/src/node_app
# this is where we will create our bundle files that we will copy over later
RUN npm run postinstall
# npm run postinstall will run the command: "webpack --mode=production"
# Actual base image of the image we are building
# We are going from the alpine version of ruby to save space
FROM ruby:2.5.1-alpine3.7
# We tell the image `--no-cache` so we don't
# clog up our image with the things we are downloading
RUN apk add --no-cache --update build-base \
linux-headers \
git \
postgresql-dev \
nodejs \
tzdata
# environment vars must be included in the dockerfile
ARG DATABASE_URL="postgres://postgres@db"
ARG RAILS_ENV=production
# copy over our Gemfile
WORKDIR /my_app
COPY Gemfile /my_app/Gemfile
COPY Gemfile.lock /my_app/Gemfile.lock
# We gem install bundler for a specific issue with bundler 2.0
# then we can bundle install
RUN gem install bundler -v 2.1.4 && bundle install
COPY . /my_app
# Here is where that build stage from earlier comes in. We need just the bundle files! So we will copy those over into
# our final image
COPY --from=build /usr/src/node_app/app/assets/javascripts/bundle.js ./app/assets/javascripts/
COPY --from=build /usr/src/node_app/app/assets/javascripts/bundle.js.map ./app/assets/javascripts/
# Add a script to be executed every time the container starts.
# This script will take care of a Rails specific Docker issue with the server
# not starting
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
# Expose our port
EXPOSE 3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]