-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathDockerfile.deb
88 lines (74 loc) · 3.68 KB
/
Dockerfile.deb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# © Copyright IBM Corporation 2019, 2025
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This Dockerfile has two separate stages.
#
# The first stage is builds the Node program, where we need tools like the C compiler for the ref-napi capability.
# It also downloads the MQ client.
# The second stage is a runtime-only container that holds just the things we need to
# execute the compiled program.
#
# Files and directories are copied from the builder container to the runtime container as needed.
# I've used two different base images, trying to get the runtime image as small
# as possible while still using a "regular" libc-based container.
###########################################################
# This starts the BUILD phase
###########################################################
FROM public.ecr.aws/ubuntu/ubuntu:20.04 as builder
# Set some parameters.
ENV NODE_VERSION 18
ENV APP_DIR /usr/local/nodejs/mqput
WORKDIR ${APP_DIR}
# Create the application directory so we can put stuff in there immediately
RUN mkdir -p ${APP_DIR}
# Update the base image and make sure we've installed basic capabilities including
# the C++ compiler needed for the FFI component. Also install node and npm.
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl gcc g++ make git ca-certificates \
&& curl --silent -k --location https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \
&& apt-get install -y nodejs \
&& npm install -g npm
# Copy project files into the container. In this source directory, the
# package file has been given a different name, to avoid any attempt to
# reference it with the rest of the samples. But it gets renamed to the
# correct name during this copy.
COPY amqsput.js ${APP_DIR}/
COPY package.docker ${APP_DIR}/package.json
# Now get all the prereq packages installed and cleanup the
# pieces that are not needed after building the C interface.
RUN npm install --omit=dev --foreground-scripts=true \
&& apt-get autoremove -y curl make gcc g++ python3 git \
&& apt-get purge -y \
&& rm -rf /var/lib/apt/lists/* \
&& chmod a+rx ${APP_DIR}/*
###########################################################
# This starts the RUNTIME phase
###########################################################
# Now that there is a container with the compiled program we can build a smaller
# runtime image. Start from one of the smaller base container images. This container
# is an official Node image with the runtime already embedded
FROM public.ecr.aws/docker/library/node:18-slim
# This is a queue predefined in the MQ Developer Edition server container. Though
# the values can be overridden by setting environment variables during the 'docker run' phase.
ENV DOCKER_Q DEV.QUEUE.1
ENV DOCKER_QMGR QM1
ENV MQSERVER SYSTEM.DEF.SVRCONN/TCP/localhost
ENV APP_DIR /usr/local/nodejs/mqput
WORKDIR ${APP_DIR}
# Copy over the tree containing the program and all its dependencies
# including the ref-napi compiled code and the MQ client libraries which
# have been installed under the node_modules directory
COPY --from=builder ${APP_DIR}/ ${APP_DIR}
# We are now ready to run the amqsput program.
RUN echo "Node Version: " && node --version
CMD node amqsput ${DOCKER_Q} ${DOCKER_QMGR}