-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
83 lines (62 loc) · 2.52 KB
/
Copy pathDockerfile
File metadata and controls
83 lines (62 loc) · 2.52 KB
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
# This is a file we use for building a Docker image for this project in production.
# 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 the most important line of this build process!
# 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"
# PHASE TWO:
# this will be the 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.5-alpine
# 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
ENV DATABASE_URL="postgres://postgres@db"
ENV RAILS_ENV=production
ENV RAILS_SERVE_STATIC_FILES=true
ENV RAILS_LOG_TO_STDOUT=true
# 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 && bundle install
COPY . /my_app
# add commands to my path
ENV PATH="/my_app/bin:${PATH}"
# Here is where that build stage from earlier comes in. We don't need all the
# Javascript dependencies 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/
RUN SECRET_KEY_BASE=1 RAILS_ENV=production bin/rake assets:precompile
# 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", "-e", "production","-b", "0.0.0.0"]