Skip to content

Commit

Permalink
Add ability to do development inside Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Apr 7, 2020
1 parent 576f2bf commit 42b5ba3
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
FROM centos:7
LABEL maintainer="[email protected]; [email protected]"

# setup the ondemand repositories
RUN yum -y install https://yum.osc.edu/ondemand/latest/ondemand-release-web-latest-1-6.noarch.rpm

# install all the dependencies
RUN yum install -y centos-release-scl && \
yum -y update && \
yum install -y \
file \
lsof \
sudo \
gcc \
gcc-c++ \
git \
patch \
ondemand-runtime \
ondemand-build \
ondemand-apache \
ondemand-ruby \
ondemand-nodejs \
ondemand-passenger \
ondemand-nginx && \
yum clean all && rm -rf /var/cache/yum/*

RUN mkdir -p /opt/ood
RUN mkdir -p /var/www/ood/{apps,public,discover}
RUN mkdir -p /var/www/ood/apps/{sys,dev,usr}

COPY mod_ood_proxy /opt/ood/mod_ood_proxy
COPY nginx_stage/ /opt/ood/nginx_stage
COPY ood-portal-generator /opt/ood/ood-portal-generator
COPY ood_auth_map /opt/ood/ood_auth_map
COPY apps /opt/ood/apps
COPY Rakefile /opt/ood/Rakefile

RUN cd /opt/ood && \
scl enable ondemand -- rake -mj4 build && \
mv /opt/ood/apps/* /var/www/ood/apps/sys/ && \
rm -rf /opt/ood/Rakefile /opt/ood/apps

# copy configuration files
RUN mkdir -p /etc/ood/config
RUN cp /opt/ood/nginx_stage/share/nginx_stage_example.yml /etc/ood/config/nginx_stage.yml
RUN cp /opt/ood/ood-portal-generator/share/ood_portal_example.yml /etc/ood/config/ood_portal.yml

# make some misc directories & files
RUN mkdir -p /var/lib/ondemand-nginx/config/apps/{sys,dev,usr}
RUN touch /var/lib/ondemand-nginx/config/apps/sys/{dashboard,shell,files,file-editor,activejobs,myjobs}.conf

# setup sudoers for apache
RUN echo -e 'Defaults:apache !requiretty, !authenticate \n\
Defaults:apache env_keep += "NGINX_STAGE_* OOD_*" \n\
apache ALL=(ALL) NOPASSWD: /opt/ood/nginx_stage/sbin/nginx_stage' >/etc/sudoers.d/ood

# run the OOD executables to setup the env
RUN /opt/ood/ood-portal-generator/sbin/update_ood_portal
RUN /opt/ood/nginx_stage/sbin/update_nginx_stage
RUN sed -i 's#HTTPD24_HTTPD_SCLS_ENABLED=.*#HTTPD24_HTTPD_SCLS_ENABLED="httpd24 ondemand"#g' /opt/rh/httpd24/service-environment
RUN groupadd ood
RUN useradd --create-home --gid ood ood
RUN echo -n "ood" | passwd --stdin ood
RUN scl enable httpd24 -- htpasswd -b -c /opt/rh/httpd24/root/etc/httpd/.htpasswd ood ood


EXPOSE 80
CMD [ "/opt/rh/httpd24/root/usr/sbin/httpd-scl-wrapper", "-DFOREGROUND" ]
27 changes: 27 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ GEMFILE = PROJ_DIR.join('Gemfile')
INSTALL_ROOT = Pathname.new(ENV["PREFIX"] || "/opt/ood")
VENDOR_BUNDLE = (ENV['VENDOR_BUNDLE'] == "yes" || ENV['VENDOR_BUNDLE'] == "true")
PASSENGER_APP_ENV = ENV["PASSENGER_APP_ENV"] || "production"
DOCKER_NAME = ENV["DOCKER_NAME"] || "ondemand-dev"
DOCKER_PORT = ENV["DOCKER_PORT"] || '8080'

def infrastructure
[
Expand Down Expand Up @@ -172,3 +174,28 @@ namespace :test do
end

task default: %w[test]

namespace :docker do
desc "Build Docker container"
task :build do
sh "docker build -t #{DOCKER_NAME} ."
end

desc "Run Docker container"
task :run do
sh "docker run -p #{DOCKER_PORT}:80 -v '#{PROJ_DIR}:/ondemand' --name #{DOCKER_NAME} --rm --detach #{DOCKER_NAME}"
end

desc "Kill Docker container"
task :kill do
sh "docker kill #{DOCKER_NAME}"
end

desc "Connect to Docker container"
task :connect do
sh "docker exec -it #{DOCKER_NAME} /bin/bash"
end

desc "Use docker to do development, build run and connect to container"
task :development => [:build, :run, :connect]
end

0 comments on commit 42b5ba3

Please sign in to comment.