11# Parent image
2- FROM hubmap/api-base-image:1.1 .0
2+ FROM hubmap/api-base-image:1.2 .0
33
44LABEL description="HuBMAP Entity API Service"
55
@@ -13,45 +13,64 @@ WORKDIR /usr/src/app
1313# Copy from host to image
1414COPY . .
1515
16- # http://nginx.org/en/linux_packages.html#RHEL-CentOS
17- # Set up the yum repository to install the latest mainline version of Nginx
18- RUN echo $'[nginx-mainline]\n \
19- name=nginx mainline repo\n \
20- baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/\n \
21- gpgcheck=1\n \
22- enabled=0\n \
23- gpgkey=https://nginx.org/keys/nginx_signing.key\n \
24- module_hotfixes=true\n ' \
25- >> /etc/yum.repos.d/nginx.repo
16+ # Set up the repository file for the mainline version of
17+ # nginx which dnf should use (in the legacy "yum" location.)
18+ RUN set -eux && \
19+ cat <<'EOF' > /etc/yum.repos.d/nginx.repo
20+ [nginx-mainline]
21+ name=nginx mainline repo
22+ baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
23+ gpgcheck=1
24+ enabled=0
25+ gpgkey=https://nginx.org/keys/nginx_signing.key
26+ module_hotfixes=true
27+ EOF
2628
2729# Reduce the number of layers in image by minimizing the number of separate RUN commands
2830# 1 - Install the prerequisites
2931# 2 - By default, the repository for stable nginx packages is used. We would like to use mainline nginx packages
30- # 3 - Install nginx (using the custom yum repo specified earlier)
32+ # 3 - Install nginx (using the custom dnf/ yum repo specified earlier)
3133# 4 - Remove the default nginx config file
3234# 5 - Overwrite the nginx.conf with ours to run nginx as non-root
3335# 6 - Remove the nginx directory copied from host machine (nginx/conf.d gets mounted to the container)
34- # 7 - Upgrade pip (the one installed in base image may be old) and install flask app dependencies (pip3 also works)
36+ # 7 - Upgrade pip (the one installed in base image may be old) and install service requirements.txt packages
3537# 8 - Make the start script executable
36- # 9 - Clean all yum cache
37- RUN yum install -y yum-utils && \
38- yum-config-manager --enable nginx-mainline && \
39- yum install -y nginx && \
40- rm /etc/nginx/conf.d/default.conf && \
41- mv nginx/nginx.conf /etc/nginx/nginx.conf && \
42- rm -rf nginx && \
43- pip install --upgrade pip -r src/requirements.txt && \
44- chmod +x start.sh && \
45- yum clean all
38+ # 9 - Clean the dnf/yum cache and other locations to reduce Docker Image layer size.
39+ # Assume the base image has upgraded dnf and installed its dnf-plugins-core
40+ RUN dnf install --assumeyes dnf-plugins-core && \
41+ dnf config-manager --enable nginx-mainline && \
42+ dnf install --assumeyes nginx && \
43+ # Push aside nginx default.conf files that may exist on the system
44+ [ ! -f /etc/nginx/conf.d/default.conf ] || mv /etc/nginx/conf.d/default.conf /tmp/etc_nginx_conf.d_default.conf.ORIGINAL && \
45+ [ ! -f /etc/nginx/nginx.conf ] || mv /etc/nginx/nginx.conf /tmp/etc_nginx_nginx.conf.ORIGINAL && \
46+ # Install the nginx default.conf file just installed in WORKDIR
47+ mv nginx/nginx.conf /etc/nginx/nginx.conf && \
48+ # Clean up the nginx install directory in WORKDIR
49+ [ ! -d nginx ] || mv nginx /tmp/nginx_from_WORKDIR && \
50+ # Push aside the verification file from the base image which will
51+ # no longer report correctly once uWSGI is started for the service.
52+ [ ! -f /tmp/verify_uwsgi.sh ] || mv /tmp/verify_uwsgi.sh /tmp/verify_uwsgi.sh.ORIGINAL && \
53+ # Install the requirements.txt file for the service
54+ pip3.13 install --no-cache-dir --upgrade pip -r src/requirements.txt && \
55+ # Make the script referenced in the CMD directive below executable.
56+ chmod 755 start.sh && \
57+ # Clean up artifacts to slim down this layer of the Docker Image
58+ dnf clean all && \
59+ rm -rf /var/cache/dnf \
60+ /var/log/dnf \
61+ /var/log/yum \
62+ /root/.cache
4663
4764# The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime.
4865# EXPOSE does not make the ports of the container accessible to the host.
4966# Here 5000 is for the uwsgi socket, 8080 for nginx
5067EXPOSE 5000 8080
5168
52- # Set an entrypoint
53- COPY entrypoint.sh /usr/local/bin/entrypoint.sh
54- RUN chmod +x /usr/local/bin/entrypoint.sh
69+ # Set an entrypoint by moving the file copied into the WORKDIR to
70+ # the location referenced by the ENTRYPOINT directive below, and
71+ # make it executable.
72+ RUN mv entrypoint.sh /usr/local/bin/entrypoint.sh && \
73+ chmod 755 /usr/local/bin/entrypoint.sh
5574
5675ENTRYPOINT ["/usr/local/bin/entrypoint.sh" ]
5776
0 commit comments