File tree Expand file tree Collapse file tree 2 files changed +52
-3
lines changed
Expand file tree Collapse file tree 2 files changed +52
-3
lines changed Original file line number Diff line number Diff line change @@ -2,9 +2,12 @@ FROM jaci/rails-base:5.2.3-alpine
22
33RUN apk add --no-cache sqlite-dev
44
5- # Bundle install Gemfile first to take advantage of caching
6- COPY ./Gemfile /app/Gemfile
7- COPY ./Gemfile.lock /app/Gemfile.lock
5+ # Copy all dependency files over before the main stuff
6+ # The reason for this is that it reduces the number of layers that
7+ # require rebuilding. If we copied all the files here, the bundle install
8+ # layer would require rebuilding every time, which is both time and space
9+ # expensive.
10+ COPY ./build/depslayer /app
811
912RUN bundle install
1013
Original file line number Diff line number Diff line change 1+ require 'fileutils'
2+
3+ DOCKER_TAG = ENV . fetch ( 'DOCKER_TAG' ) { "#{ `git rev-parse --short HEAD` . strip } #{ `git diff HEAD --quiet || echo -dirty` . strip } " }
4+ DOCKER_REPO = ENV . fetch ( 'DOCKER_REPO' ) { "gcr.io/imjacinta/jaci/curtincourses" }
5+
6+ DOCKER_IMG = "#{ DOCKER_REPO } :#{ DOCKER_TAG } "
7+
8+ def copy_deps
9+ FileUtils . mkdir_p 'build/depslayer'
10+ Dir . glob ( [ '**/Gemfile' , '**/Gemfile.lock' , '**/*.gemspec' ] ) . each do |file |
11+ next if file . include? ( 'build/depslayer' )
12+
13+ dest = "build/depslayer/#{ file } "
14+ FileUtils . mkdir_p ( File . dirname ( dest ) )
15+
16+ if !File . exist? ( dest ) || File . read ( file ) != File . read ( dest )
17+ puts "Update: #{ file } -> #{ dest } "
18+ FileUtils . cp ( file , dest )
19+ end
20+ end
21+ end
22+
23+ def docker_build
24+ copy_deps
25+ system "docker build -t #{ DOCKER_IMG } ."
26+ end
27+
28+ def docker_push
29+ docker_build
30+ system "docker push #{ DOCKER_IMG } "
31+ end
32+
33+ if __FILE__ == $0
34+ act = ARGV [ 0 ]
35+ if act == 'build'
36+ docker_build
37+ elsif act == 'push'
38+ docker_push
39+ elsif act == 'get_tag'
40+ puts DOCKER_TAG
41+ elsif act == 'get_img'
42+ puts DOCKER_IMG
43+ elsif act == 'get_repo'
44+ puts DOCKER_REPO
45+ end
46+ end
You can’t perform that action at this time.
0 commit comments