-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1945 from 18F/docker-support
Docker support(Update)
- Loading branch information
Showing
5 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM ruby:2.3.1 | ||
|
||
# set locales | ||
RUN apt-get update >/dev/null && \ | ||
apt-get install -y locales >/dev/null && \ | ||
echo "en_US UTF-8" > /etc/locale.gen && \ | ||
locale-gen en_US.UTF-8 && \ | ||
export LANG=en_US.UTF-8 && \ | ||
export LANGUAGE=en_US:en && \ | ||
export LC_ALL=en_US.UTF-8 | ||
|
||
RUN curl -sL https://deb.nodesource.com/setup_4.x | bash - && \ | ||
apt-get install -y nodejs | ||
|
||
|
||
COPY Gemfile Gemfile.lock /app/ | ||
|
||
RUN cd /app && gem install bundler && bundle install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
app: | ||
build: ./ | ||
working_dir: /app | ||
volumes: | ||
- .:/app | ||
entrypoint: ruby /app/docker_entrypoint.rb | ||
command: ./serve | ||
ports: | ||
- "4000:4000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'etc' | ||
|
||
# We want our Docker process to use the same uid as the owner of the | ||
# repository checkout. This will ensure that any created files | ||
# have the same owner and can be accessed on the host system, rather than | ||
# being owned by root and hard to modify or delete. | ||
HOST_UID = File::Stat.new('/app').uid | ||
|
||
# This is just the username for the uid, for cosmetic purposes only really. | ||
HOST_USER = '18f_user'.freeze | ||
|
||
def does_username_exist(username) | ||
Etc.getpwnam(username) | ||
true | ||
rescue ArgumentError | ||
false | ||
end | ||
|
||
def does_uid_exist(uid) | ||
Etc.getpwuid(uid) | ||
true | ||
rescue ArgumentError | ||
false | ||
end | ||
|
||
def assume_uid | ||
unless does_uid_exist(HOST_UID) | ||
username = HOST_USER | ||
username += '0' while does_username_exist(username) | ||
home_dir = '/home/' + username | ||
system("useradd -d #{home_dir} -m #{username} -u #{HOST_UID}") | ||
end | ||
ENV['HOME'] = '/home/' + Etc.getpwuid(HOST_UID).name | ||
Process::UID.change_privilege(HOST_UID) | ||
return unless Process.euid != HOST_UID | ||
end | ||
|
||
assume_uid | ||
|
||
exec(*ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters