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,62 @@ 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 stable 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-stable]
21+ name=nginx stable repo
22+ baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
23+ gpgcheck=1
24+ enabled=1
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
29- # 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)
31+ # 2 - By default, the repository for stable nginx packages is used.
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 nginx && \
41+ # Push aside nginx default.conf files that may exist on the system
42+ [ ! -f /etc/nginx/conf.d/default.conf ] || mv /etc/nginx/conf.d/default.conf /tmp/etc_nginx_conf.d_default.conf.ORIGINAL && \
43+ [ ! -f /etc/nginx/nginx.conf ] || mv /etc/nginx/nginx.conf /tmp/etc_nginx_nginx.conf.ORIGINAL && \
44+ # Install the nginx default.conf file just installed in WORKDIR
45+ mv nginx/nginx.conf /etc/nginx/nginx.conf && \
46+ # Clean up the nginx install directory in WORKDIR
47+ [ ! -d nginx ] || mv nginx /tmp/nginx_from_WORKDIR && \
48+ # Push aside the verification file from the base image which will
49+ # no longer report correctly once uWSGI is started for the service.
50+ [ ! -f /tmp/verify_uwsgi.sh ] || mv /tmp/verify_uwsgi.sh /tmp/verify_uwsgi.sh.ORIGINAL && \
51+ # Install the requirements.txt file for the service
52+ pip3.13 install --no-cache-dir --upgrade pip -r src/requirements.txt && \
53+ # Make the script referenced in the CMD directive below executable.
54+ chmod a+x start.sh && \
55+ # Clean up artifacts to slim down this layer of the Docker Image
56+ dnf clean all && \
57+ rm -rf /var/cache/dnf \
58+ /var/log/dnf \
59+ /var/log/yum \
60+ /root/.cache
4661
4762# The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime.
4863# EXPOSE does not make the ports of the container accessible to the host.
4964# Here 5000 is for the uwsgi socket, 8080 for nginx
5065EXPOSE 5000 8080
5166
52- # Set an entrypoint
53- COPY entrypoint.sh /usr/local/bin/entrypoint.sh
54- RUN chmod +x /usr/local/bin/entrypoint.sh
67+ # Set an entrypoint by moving the file copied into the WORKDIR to
68+ # the location referenced by the ENTRYPOINT directive below, and
69+ # make it executable.
70+ RUN mv entrypoint.sh /usr/local/bin/entrypoint.sh && \
71+ chmod a+x /usr/local/bin/entrypoint.sh
5572
5673ENTRYPOINT ["/usr/local/bin/entrypoint.sh" ]
5774
0 commit comments