|
10 | 10 | #
|
11 | 11 | # docker buildx build \
|
12 | 12 | # --platform linux/amd64,linux/arm64 \
|
13 |
| -# --tag mtconnect/agent:2.0.0.12_RC18 \ |
| 13 | +# --tag mtconnect/demo:latest \ |
14 | 14 | # --push \
|
| 15 | +# -f demo/Dockerfile |
15 | 16 | # .
|
16 | 17 | #
|
17 | 18 | # To run tests, use `--build-arg WITH_TESTS=true`
|
18 | 19 | #
|
19 | 20 | # # Note: In this case, I would suggest to map port `5000` to `5000`. The user can always change the port according to their needs.
|
20 |
| -# docker run -it --rm --init --name agent -p5000:5000 \ |
21 |
| -# mtconnect/agent:2.0.0.12_RC18 |
| 21 | +# docker run -it --rm --init --name agent -p5000:5000 mtconnect/demo |
22 | 22 | #
|
23 | 23 | # then visit http://localhost:5000 to see the demo output.
|
24 | 24 |
|
25 | 25 | # ---------------------------------------------------------------------
|
26 |
| -# os |
| 26 | +# Use the mtconnect/agent base image |
27 | 27 | # ---------------------------------------------------------------------
|
28 |
| - |
29 |
| -# base image - ubuntu has amd64, arm64 etc. |
30 |
| -# 22.04 is the current long term support release, maintained until 2025-04. |
31 |
| -FROM ubuntu:22.04 AS os |
32 |
| - |
33 |
| -# tzinfo hangs without this |
34 |
| -ARG DEBIAN_FRONTEND='noninteractive' |
35 |
| - |
36 |
| -# --------------------------------------------------------------------- |
37 |
| -# build |
38 |
| -# --------------------------------------------------------------------- |
39 |
| - |
40 |
| -FROM os AS build |
41 |
| - |
42 |
| -# limit cpus so don't run out of memory on local machine |
43 |
| -# symptom: get error - "c++: fatal error: Killed signal terminated program cc1plus" |
44 |
| -# can turn off if building in cloud |
45 |
| -ARG CONAN_CPU_COUNT=2 |
46 |
| - |
47 |
| -ARG WITH_RUBY='True' |
48 |
| - |
49 |
| -# set some variables |
50 |
| -ENV PATH="$HOME/venv3.9/bin:$PATH" |
51 |
| -ENV CONAN_PROFILE='conan/profiles/docker' |
52 |
| - |
53 |
| -# update os and add dependencies |
54 |
| -# note: Dockerfiles run as root by default, so don't need sudo |
55 |
| -RUN apt-get update \ |
56 |
| - && apt-get install -y \ |
57 |
| - autoconf \ |
58 |
| - automake \ |
59 |
| - build-essential \ |
60 |
| - cmake \ |
61 |
| - git \ |
62 |
| - python3 \ |
63 |
| - python3-pip \ |
64 |
| - rake \ |
65 |
| - ruby \ |
66 |
| - && rm -rf /var/lib/apt/lists/* \ |
67 |
| - && pip install conan -v 'conan==2.0.9' |
68 |
| - |
69 |
| -# make an agent directory and cd into it |
70 |
| -WORKDIR /root/agent |
71 |
| - |
72 |
| -# bring in the repo contents, minus .dockerignore files |
73 |
| -COPY . . |
74 |
| - |
75 |
| -ARG WITH_TESTS=false |
76 |
| -ARG WITH_TESTS_ARG=argument |
77 |
| -ARG SHARED=False |
78 |
| - |
79 |
| -# Build and optionally test |
80 |
| -RUN if [ -z "$WITH_TESTS" ] || [ "$WITH_TESTS" = "false" ]; then \ |
81 |
| - WITH_TESTS_ARG="--test-folder="; \ |
82 |
| - else \ |
83 |
| - WITH_TESTS_ARG=""; \ |
84 |
| - fi \ |
85 |
| - && conan profile detect \ |
86 |
| - && conan create . \ |
87 |
| - --build=missing \ |
88 |
| - -c "tools.build:jobs=$CONAN_CPU_COUNT" \ |
89 |
| - -o agent_prefix=mtc \ |
90 |
| - -o cpack=True \ |
91 |
| - -o "with_ruby=$WITH_RUBY" \ |
92 |
| - -o cpack_destination=/root/agent \ |
93 |
| - -o cpack_name=dist \ |
94 |
| - -o cpack_generator=TGZ \ |
95 |
| - -pr "$CONAN_PROFILE" \ |
96 |
| - ${WITH_TESTS_ARG} |
97 |
| - |
98 |
| -# --------------------------------------------------------------------- |
99 |
| -# release |
100 |
| -# --------------------------------------------------------------------- |
101 |
| - |
102 |
| -FROM os AS release |
| 28 | +FROM mtconnect/agent as mtconnect |
103 | 29 |
|
104 | 30 | # TODO: How about shortening the description to MTConnect Agent or at least MTConnect C++ Agent?
|
105 |
| -LABEL author='mtconnect' description='MTConnect C++ Agent' |
106 |
| - |
107 |
| -ARG BIN_DIR='/usr/local/bin' |
108 |
| -ARG LIB_DIR='/usr/local/lib' |
109 |
| - |
110 |
| -ARG MTCONNECT_CONF_DIR='/etc/mtconnect' |
111 |
| -ARG MTCONNECT_DATA_DIR='/usr/local/share/mtconnect' |
112 |
| -ARG MTCONNECT_LOG_DIR='/var/log/mtconnect' |
| 31 | +LABEL author='mtconnect' description='MTConnect C++ Agent Demo' |
113 | 32 |
|
114 |
| -ENV MTCONNECT_CONF_DIR="$MTCONNECT_CONF_DIR" |
115 |
| -ENV MTCONNECT_DATA_DIR="$MTCONNECT_DATA_DIR" |
116 |
| -ENV MTCONNECT_LOG_DIR="$MTCONNECT_LOG_DIR" |
117 |
| -ENV DEMO_DIR="$MTCONNECT_DATA_DIR/demo" |
118 |
| - |
119 |
| -# install ruby for simulator |
120 |
| -RUN apt-get update \ |
121 |
| - && apt-get install -y ruby |
| 33 | +USER root |
122 | 34 |
|
123 |
| -# change to a new non-root user for better security. |
124 |
| -# this also adds the user to a group with the same name. |
125 |
| -# -m creates a home folder, ie /home/<username> |
126 |
| -ARG UID=1000 |
127 |
| -ARG GID=1000 |
| 35 | +RUN apk add ruby |
128 | 36 |
|
129 |
| -RUN groupadd \ |
130 |
| - --gid $GID \ |
131 |
| - agent \ |
132 |
| - && useradd \ |
133 |
| - --create-home \ |
134 |
| - --uid $UID \ |
135 |
| - --gid $GID \ |
136 |
| - agent |
| 37 | +COPY --chown=agent:agent \ |
| 38 | + ./simulator/* \ |
| 39 | + /mtconnect/data/simulator/ |
| 40 | +COPY --chown=agent:agent \ |
| 41 | + ./demo/ \ |
| 42 | + /mtconnect/data/demo/ |
| 43 | +COPY --chown=agent:agent \ |
| 44 | + ./demo/agent/agent.dock \ |
| 45 | + ./demo/agent/Devices.xml \ |
| 46 | + /mtconnect/config/ |
137 | 47 |
|
138 | 48 | USER agent
|
139 | 49 | WORKDIR /home/agent
|
140 | 50 |
|
141 |
| -# install agent executable |
142 |
| -COPY --chown=agent:agent --from=build /root/agent/dist.tar.gz /home/agent/ |
143 |
| - |
144 |
| -# Extract the data |
145 |
| -RUN tar xf dist.tar.gz \ |
146 |
| - && rm dist.tar.gz |
147 |
| - |
148 |
| -# Copy the agent binary and create folders used by the agent |
149 |
| -USER root |
150 |
| -RUN mkdir -p "$BIN_DIR" "$LIB_DIR" \ |
151 |
| - && cp /home/agent/dist/bin/* "$BIN_DIR" \ |
152 |
| - && cp /home/agent/dist/lib/* "$LIB_DIR" \ |
153 |
| - && mkdir -p "$MTCONNECT_CONF_DIR" \ |
154 |
| - "$MTCONNECT_DATA_DIR" \ |
155 |
| - "$MTCONNECT_LOG_DIR" \ |
156 |
| - && chown agent:agent "$MTCONNECT_CONF_DIR" \ |
157 |
| - "$MTCONNECT_DATA_DIR" \ |
158 |
| - "$MTCONNECT_LOG_DIR" |
159 |
| - |
160 |
| -USER agent |
161 |
| - |
162 |
| -# Copy the agent data |
163 |
| -RUN cp -r /home/agent/dist/share/mtconnect/schemas \ |
164 |
| - /home/agent/dist/share/mtconnect/simulator \ |
165 |
| - /home/agent/dist/share/mtconnect/styles \ |
166 |
| - /home/agent/dist/share/mtconnect/demo \ |
167 |
| - "$MTCONNECT_DATA_DIR" \ |
168 |
| - && cp /home/agent/dist/share/mtconnect/demo/agent/agent.dock "$MTCONNECT_CONF_DIR/agent.cfg" \ |
169 |
| - && cp /home/agent/dist/share/mtconnect/demo/agent/Devices.xml "$MTCONNECT_CONF_DIR" \ |
170 |
| - && rm -r /home/agent/dist |
171 |
| - |
172 | 51 | # expose port
|
173 | 52 | EXPOSE 5000
|
174 | 53 |
|
| 54 | +# Allow the directories to be mounted |
| 55 | +VOLUME ["/mtconnect/config", "/mtconnect/log", "/mtconnect/data"] |
| 56 | + |
175 | 57 | # default command - can override with docker run or docker-compose command.
|
176 | 58 | # this runs the adapter simulator and the agent using the sample config file.
|
177 | 59 | # note: must use shell form here instead of exec form, since we're running
|
178 | 60 | # multiple statements using shell commands (& and &&).
|
179 | 61 | # see https://stackoverflow.com/questions/46797348/docker-cmd-exec-form-for-multiple-command-execution
|
180 |
| -CMD /usr/bin/ruby "$MTCONNECT_DATA_DIR/simulator/run_scenario.rb" -p 7879 -l "$DEMO_DIR/agent/mazak.txt" \ |
181 |
| - & /usr/bin/ruby "$MTCONNECT_DATA_DIR/simulator/run_scenario.rb" -p 7878 -l "$DEMO_DIR/agent/okuma.txt" \ |
182 |
| - & mtcagent run |
| 62 | + |
| 63 | +CMD /usr/bin/ruby /mtconnect/data/simulator/run_scenario.rb -p 7879 -l /mtconnect/data/demo/agent/mazak.txt \ |
| 64 | + & /usr/bin/ruby /mtconnect/data/simulator/run_scenario.rb -p 7878 -l /mtconnect/data/demo/agent/okuma.txt \ |
| 65 | + & mtcagent run /mtconnect/config/agent.dock |
183 | 66 |
|
184 | 67 | # ---------------------------------------------------------------------
|
185 | 68 | # note
|
186 | 69 | # ---------------------------------------------------------------------
|
187 | 70 |
|
188 | 71 | # after setup, the dirs look like this -
|
189 | 72 | #
|
190 |
| -# /usr/local/bin |
| 73 | +# /usr/bin |
191 | 74 | # |-- agent - the cppagent application
|
192 | 75 | #
|
193 |
| -# /etc/mtconnect - Configuration files agent.cfg and Devices.xml |
| 76 | +# /mtconnect/config - Configuration files agent.cfg and Devices.xml |
194 | 77 | #
|
195 |
| -# /usr/local/share/mtconnect |
| 78 | +# /mtconnect/data |
196 | 79 | # |-- schemas - xsd files
|
197 |
| -# |-- simulator - agent.cfg, simulator.rb, vmc-3axis.xml, log.txt |
198 | 80 | # |-- styles - styles.xsl, styles.css, favicon.ico, etc
|
199 | 81 | #
|
200 | 82 | # /home/agent - the user's directory
|
201 | 83 | #
|
202 |
| -# /var/log/mtconnect - logging directory |
| 84 | +# /mtconnect/log - logging directory |
0 commit comments