cppagent: `v2.2.0.3`: ERROR: /root/agent/conanfile.py: option 'build_tests' doesn't exist

I wanted to build a Docker image for v2.2.0.3 with the same instructions I used to build an image for v2.1.0.6, however, the build fails with the following error:

# docker buildx build --no-cache \
#   -f "$repo_path/Dockerfile" \
#   --platform linux/amd64,linux/arm64 \
#   -t ladder99/agent:v2.2.0.3 \
#   -t ladder99/agent:latest \
#   "$repo_path"
0.982 ************************* WARNING: GCC OLD ABI COMPATIBILITY ***********************                                                                                                                                                   
0.982                                                                                                                                                                                                                                        
0.982 Conan detected a GCC version > 5 but has adjusted the 'compiler.libcxx' setting to                                                                                                                                                     
0.982 'libstdc++' for backwards compatibility.                                                                                                                                                                                               
0.982 Your compiler is likely using the new CXX11 ABI by default (libstdc++11).
0.982 
0.982 If you want Conan to use the new ABI for the default profile, run:
0.982 
0.982     $ conan profile update settings.compiler.libcxx=libstdc++11 default
0.982 
0.982 Or edit '/root/.conan/profiles/default' and set compiler.libcxx=libstdc++11
0.982 
0.982 ************************************************************************************
0.982 
0.982 
0.982 
0.982 Default settings
0.982    os=Linux
0.982    os_build=Linux
0.982    arch=x86_64
0.982    arch_build=x86_64
0.982    compiler=gcc
0.982    compiler.version=11
0.982    compiler.libcxx=libstdc++
0.982    build_type=Release
0.982 *** You can change them in /root/.conan/profiles/default ***
0.982 *** Or override with -s compiler='other' -s ...s***
0.982 
0.982 
1.036 Configuration:
1.036 [settings]
1.036 arch=x86_64
1.036 arch_build=x86_64
1.036 build_type=Release
1.036 compiler=gcc
1.036 compiler.libcxx=libstdc++11
1.036 compiler.version=11
1.036 os=Linux
1.036 os_build=Linux
1.036 [options]
1.036 build_tests=False
1.036 run_tests=False
1.036 with_ruby=True
1.036 without_ipv6=True
1.036 [build_requires]
1.036 [env]
1.036 
1.038 ERROR: /root/agent/conanfile.py: option 'build_tests' doesn't exist
1.038 Possible options are ['without_ipv6', 'with_ruby', 'development', 'shared', 'winver', 'with_docs', 'cpack', 'agent_prefix', 'fPIC']
------
Dockerfile:64
--------------------
  63 |     # make installer
  64 | >>> RUN conan export conan/mqtt_cpp \
  65 | >>>   && conan export conan/mruby \
  66 | >>>   && conan install . -if build --build=missing \
  67 | >>>   -pr $CONAN_PROFILE \
  68 | >>>   -o build_tests=$WITH_TESTS \
  69 | >>>   -o run_tests=$WITH_TESTS \
  70 | >>>   -o with_ruby=$WITH_RUBY
  71 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c conan export conan/mqtt_cpp   && conan export conan/mruby   && conan install . -if build --build=missing   -pr $CONAN_PROFILE   -o build_tests=$WITH_TESTS   -o run_tests=$WITH_TESTS   -o with_ruby=$WITH_RUBY" did not complete successfully: exit code: 1

Now, the issue seems to stem from the changes (see esp changes on these lines) in conanfile.py between v2.1.0.6 and v2.2.0.3, as there is no such command (or how do you call it) as build_tests (it seems to be removed). If build_tests option should be removed, then the Dockerfile and Dockerfile.alpine files should be updated accordingly:

I have tried to build AMD64 and ARM64 multiarch image using Dockerfile (but not using Dockerfile.alpine) with the changes listed above, however, the build fails with TypeError: ConanFile.run() got an unexpected keyword argument 'stdout' in conan/mruby/conanfile.py (L187). FYI, ubuntu:22.04 currently installs the following ruby version: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu].

Build error after removing the lines
# docker buildx build --no-cache \
#   -f "$repo_path/Dockerfile" \
#   --platform linux/amd64,linux/arm64 \
#   -t ladder99/agent:v2.2.0.3 \
#   -t ladder99/agent:latest \
#   "$repo_path"
545.6 Build summary:
545.6 
545.6 ================================================
545.6       Config Name: host
545.6  Output Directory: ../build-release/host
545.6          Binaries: mruby-config, mrbc
545.6     Included Gems:
545.6              mruby-array-ext - Array class extension
545.6              mruby-bigint - Integer class extension to multiple-precision
545.6              mruby-bin-config - mruby-config command
545.6              mruby-bin-mrbc - mruby compiler executable
545.6              mruby-bin-mruby - mruby command
545.6                - Binaries: mruby
545.6              mruby-bin-strip - irep dump debug section remover command
545.6                - Binaries: mruby-strip
545.6              mruby-binding - Binding class
545.6              mruby-binding-core - Binding class (core features only)
545.6              mruby-catch - Catch / Throw non-local Jump
545.6              mruby-class-ext - class/module extension
545.6              mruby-cmath - standard Math module with complex
545.6              mruby-compar-ext - Comparable module extension
545.6              mruby-compiler - mruby compiler library
545.6              mruby-complex - Complex class
545.6              mruby-data - standard Data class
545.6              mruby-dir
545.6              mruby-enum-chain - Enumerator::Chain class
545.6              mruby-enum-ext - Enumerable module extension
545.6              mruby-enum-lazy - Enumerator::Lazy class
545.6              mruby-enumerator - Enumerator class
545.6              mruby-errno - Errno module and SystemCallError class
545.6              mruby-error - extensional error handling
545.6              mruby-eval - standard Kernel#eval method
545.6              mruby-exit - Kernel#exit method
545.6              mruby-fiber - Fiber class
545.6              mruby-hash-ext - Hash class extension
545.6              mruby-io - IO and File class
545.6              mruby-kernel-ext - extensional function-like methods
545.6              mruby-math - standard Math module
545.6              mruby-metaprog - Meta-programming features for mruby
545.6              mruby-method - Method and UnboundMethod class
545.6              mruby-numeric-ext - Numeric class extension
545.6              mruby-object-ext - extensional methods shared by all objects
545.6              mruby-objectspace - ObjectSpace class
545.6              mruby-onig-regexp
545.6              mruby-os-memsize - ObjectSpace memsize_of method
545.6              mruby-pack - Array#pack and String#unpack method
545.6              mruby-print - standard print/puts/p
545.6              mruby-proc-binding - Proc#binding method
545.6              mruby-proc-ext - Proc class extension
545.6              mruby-random - Random class
545.6              mruby-range-ext - Range class extension
545.6              mruby-rational - Rational class
545.6              mruby-require
545.6              mruby-set
545.6              mruby-sleep - Kernel#sleep and Kernel#usleep
545.6              mruby-socket - standard socket class
545.6              mruby-sprintf - standard Kernel#sprintf method
545.6              mruby-string-ext - String class extension
545.6              mruby-struct - standard Struct class
545.6              mruby-symbol-ext - Symbol class extension
545.6              mruby-test-inline-struct - inline structure
545.6              mruby-time - standard Time class
545.6              mruby-toplevel-ext - toplevel object (main) methods extension
545.6 ================================================
545.6 
545.6 ================================================
545.6       Config Name: host/mrbc
545.6  Output Directory: ../build-release/host/mrbc
545.6          Binaries: mrbc
545.6     Included Gems:
545.6              mruby-bin-mrbc - mruby compiler executable
545.6              mruby-compiler - mruby compiler library
545.6 ================================================
545.6 
545.6 mruby/3.2.0: Package 'f78302de80edd0f6a872b1440636d3069d3a5347' built
545.6 mruby/3.2.0: Build folder /root/.conan/data/mruby/3.2.0/_/_/build/f78302de80edd0f6a872b1440636d3069d3a5347/build-release
545.6 mruby/3.2.0: Generated conaninfo.txt
545.6 mruby/3.2.0: Generated conanbuildinfo.txt
545.6 mruby/3.2.0: Generating the package
545.6 mruby/3.2.0: Package folder /root/.conan/data/mruby/3.2.0/_/_/package/f78302de80edd0f6a872b1440636d3069d3a5347
545.6 mruby/3.2.0: Calling package()
545.7 mruby/3.2.0: Copied 4 files: mruby, mrbc, mruby-strip, mruby-config
545.7 mruby/3.2.0: Copied 2 '.a' files: libmruby.a, libmruby_core.a
545.7 mruby/3.2.0: Copied 1 '.mak' file: libmruby.flags.mak
545.7 mruby/3.2.0: Copied 2 '.h' files: table.h, id.h
545.7 mruby/3.2.0: Copied 36 '.h' files
545.7 mruby/3.2.0: Copied 11 '.h' files
545.8 mruby/3.2.0 package(): Packaged 2 '.a' files: libmruby.a, libmruby_core.a
545.8 mruby/3.2.0 package(): Packaged 1 '.mak' file: libmruby.flags.mak
545.8 mruby/3.2.0 package(): Packaged 4 files: mruby, mrbc, mruby-strip, mruby-config
545.8 mruby/3.2.0 package(): Packaged 49 '.h' files
545.8 mruby/3.2.0: Package 'f78302de80edd0f6a872b1440636d3069d3a5347' created
545.8 mruby/3.2.0: Created package revision 5e1ebc1caeaf88a5999859f118b63a78
545.8 ERROR: mruby/3.2.0: Error in package_info() method, line 187
545.8    self.run("{} --cflags".format(ruby), stdout=buf, shell=True)
545.8    TypeError: ConanFile.run() got an unexpected keyword argument 'stdout'
------
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile:63
--------------------
  62 |     # make installer
  63 | >>> RUN conan export conan/mqtt_cpp \
  64 | >>>   && conan export conan/mruby \
  65 | >>>   && conan install . -if build --build=missing \
  66 | >>>   -pr $CONAN_PROFILE \
  67 | >>>   -o with_ruby=$WITH_RUBY
  68 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c conan export conan/mqtt_cpp   && conan export conan/mruby   && conan install . -if build --build=missing   -pr $CONAN_PROFILE   -o with_ruby=$WITH_RUBY" did not complete successfully: exit code: 1

I have found a similar conan issue (conan-io/conan#5670), although that is about win_bash=True instead of shell=True, however, removing shell=True didn’t help to work around the issue. Then I tried to change the line to self.run("{} --cflags".format(ruby), output=buf) (based on the line version from v2.1.0.6), but that failed too (self.run("{} --cflags".format(ruby), shell=True) also failed). It fails in cppagent/conanfile.py (L157) with ConanException: CMakePresets.json was not found in /root/agent/build/build/Release/generators folder. Check that you are using CMakeToolchain as generator to ensure its correct initialization..

Build error after removing the lines and changing a line in conan/mruby/conanfile.py
# docker buildx build \
#   -f "$repo_path/Dockerfile" \
#   --platform linux/amd64,linux/arm64 \
#   -t ladder99/agent:v2.2.0.3 \
#   -t ladder99/agent:latest \
#   "$repo_path"
1.658 conanfile.py (mtconnect_agent/2.2): Calling build()                                                                                                                                                                                    
1.658 ERROR: conanfile.py (mtconnect_agent/2.2): Error in build() method, line 157
1.658    cmake = CMake(self)
1.658    ConanException: CMakePresets.json was not found in /root/agent/build/build/Release/generators folder. Check that you are using CMakeToolchain as generator to ensure its correct initialization.
------
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile:70
--------------------
  68 |     
  69 |     # compile source (~20mins - 4hrs for qemu)
  70 | >>>  RUN conan build . -bf build
  71 |     
  72 |     # ---------------------------------------------------------------------
--------------------
ERROR: failed to solve: process "/bin/sh -c conan build . -bf build" did not complete successfully: exit code: 1

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

Sounds good. We can move this work to your branch since the current branch I was working on was originally for CI/CD

Just completed a new version of the Dockerfile for ubuntu. It now works. Also using the demo scripts. Still need to get the twin demo working through docker. The rest works perfectly.

I tested the ARM build and is running fine.

MTConnect Agent Version 2.2.0.2 (_RC5) - built on Wed Aug 2 16:15:24 2023

@wsobel, I think I have fixed Dockerfile; at least it builds successfully a multiarch image, I am able to create a container and open localhost:5000 (I haven’t tested it with real machine, only the built-in simulator which does not reason generate any data, just waits for data on port 7878).

Now, I’d like to review my changes and tell me if you’d like me to change anything (configuration-wise). Tell me your opinion. Then I could open a PR with the changes—or do you want to do it yourself? 🤔

Anyway, building the multiarch image on my mobile workstation laptop with 12-core CPU and 46 GB RAM took 1h 51m (with CONAN_CPU_COUNT=10). With CONAN_CPU_COUNT=2, building the image took me 2h 1m.

Dockerfile diff
diff --git a/Dockerfile b/Dockerfile
index e3de82ae..e48a0723 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,6 @@
 # MTConnect Public C++ Agent Docker image build instructions
 
+# TODO: Do we need notes like this to be in `Dockerfile`? I think the docs might be a better place for this. IMHO most notes in this file should be moved to the docs.
 # ---------------------------------------------------------------------
 # notes
 # ---------------------------------------------------------------------
@@ -13,6 +14,7 @@
 #     --push \
 #     .
 #
+#   # Note: In this case, I would suggest to map port `5000` to `5000`. The user can always change the port according to their needs.
 #   docker run -it --rm --init --name agent -p5001:5000 \
 #     mtconnect/agent:2.0.0.12_RC18
 #
@@ -24,7 +26,10 @@
 
 # base image - ubuntu has amd64, arm64 etc.
 # 22.04 is the current long term support release, maintained until 2025-04.
-FROM ubuntu:22.04 AS os
+# Note: We need to use 22.10+, as 22.04 has `cmake@3.22.1` available only,
+#       however, we need to use `cmake@3.23+`. Another option is to build it
+#       from sources, which would increase the MTConnect Agent build time.
+FROM ubuntu:22.10 AS os
 
 # tzinfo hangs without this
 ARG DEBIAN_FRONTEND=noninteractive
@@ -40,8 +45,18 @@ FROM os AS build
 RUN apt-get clean \
   && apt-get update \
   && apt-get install -y \
-  build-essential python3.9 python3-pip git cmake make ruby rake autoconf automake \
-  && pip install conan -v "conan==1.59.0"
+    autoconf \
+    automake \
+    build-essential \
+    cmake \
+    g++-11 \
+    gcc-11 \
+    git \
+    python3 \
+    python3-pip \
+    rake \
+    ruby \
+  && pip install conan
 
 # make an agent directory and cd into it
 WORKDIR /root/agent
@@ -51,26 +66,32 @@ COPY . .
 
 # set some variables
 ENV PATH=$HOME/venv3.9/bin:$PATH
-ENV CONAN_PROFILE=conan/profiles/docker
+# Note: When using `conan/profiles/docker` profile, the build errors out at `[env]`.
+ENV CONAN_PROFILE=conan/profiles/gcc
+# TODO: I think we should hardcode `SHARED` value.
+ENV SHARED=False
+# TODO: Do we need these two variables? They have a default value (even `SHARED` is set to a default value). We might want to remove options with default values.
 ENV WITH_RUBY=True
 ENV WITH_TESTS=False
 
 # limit cpus so don't run out of memory on local machine
 # symptom: get error - "c++: fatal error: Killed signal terminated program cc1plus"
 # can turn off if building in cloud
-ENV CONAN_CPU_COUNT=1
+# Note: I have build this image on a machine 12-core CPU, 48 GB of RAM, therefore the build time for ARM64 was nearly the as the build time for AMD64 (ARM64 was slower by 2 minutes in the first `conan` command). Of course, it can be reverted to `1`, maybe to `2`, as we build two images for two archs.
+ENV CONAN_CPU_COUNT=10
 
 # make installer
-RUN conan export conan/mqtt_cpp \
-  && conan export conan/mruby \
-  && conan install . -if build --build=missing \
-  -pr $CONAN_PROFILE \
-  -o build_tests=$WITH_TESTS \
-  -o run_tests=$WITH_TESTS \
-  -o with_ruby=$WITH_RUBY
-
+# FIXME: Before commiting, run these two commands in one `RUN`.
+RUN conan profile detect -f
 # compile source (~20mins - 4hrs for qemu)
- RUN conan build . -bf build
+# TODO: What should be the `shared` value? In GitLab CI, it is set to `${{ matrix.shared }}` and `matrix.shared` to `["True", "False"]`.
+RUN conan build . \
+  --build=missing \
+  -pr "$CONAN_PROFILE" \
+  -o cpack=True \
+  -o "shared=$SHARED" \
+  -o with_docs=False \
+  -o without_ipv6=False
 
 # ---------------------------------------------------------------------
 # release
@@ -90,7 +111,7 @@ RUN useradd --create-home agent
 USER agent
 
 # install agent executable
-COPY --chown=agent:agent --from=build /root/agent/build/bin/agent /usr/local/bin/
+COPY --chown=agent:agent --from=build /root/agent/build/static-*/Release/agent/agent /usr/local/bin
 
 # copy data to /etc/mtconnect
 COPY --chown=agent:agent --from=build /root/agent/schemas /etc/mtconnect/schemas
@@ -104,13 +125,13 @@ WORKDIR /home/agent
 
 # default command - can override with docker run or docker-compose command.
 # this runs the adapter simulator and the agent using the sample config file.
-# note: must use shell form here instead of exec form, since we're running 
+# note: must use shell form here instead of exec form, since we're running
 # multiple statements using shell commands (& and &&).
 # see https://stackoverflow.com/questions/46797348/docker-cmd-exec-form-for-multiple-command-execution
+# TODO: There is no `mtcagent` available. Was it renamed to `agent`?
 CMD /usr/bin/ruby /etc/mtconnect/simulator/run_scenario.rb -l \
   /etc/mtconnect/simulator/VMC-3Axis-Log.txt & \
-  cd /etc/mtconnect/simulator && mtcagent run agent.cfg
-
+  cd /etc/mtconnect/simulator && agent run agent.cfg
 
 # ---------------------------------------------------------------------
 # note
Entire Dockerfile
# MTConnect Public C++ Agent Docker image build instructions

# TODO: Do we need notes like this to be in `Dockerfile`? I think the docs might be a better place for this. IMHO most notes in this file should be moved to the docs.
# ---------------------------------------------------------------------
# notes
# ---------------------------------------------------------------------
#
# to build a cross-platform image, push to docker hub, and run it -
# (see CMakeLists.txt for current version number) -
#
#   docker buildx build \
#     --platform linux/amd64,linux/arm64 \
#     --tag mtconnect/agent:2.0.0.12_RC18 \
#     --push \
#     .
#
#   # Note: In this case, I would suggest to map port `5000` to `5000`. The user can always change the port according to their needs.
#   docker run -it --rm --init --name agent -p5001:5000 \
#     mtconnect/agent:2.0.0.12_RC18
#
# then visit http://localhost:5001 to see the demo output.

# ---------------------------------------------------------------------
# os
# ---------------------------------------------------------------------

# base image - ubuntu has amd64, arm64 etc.
# 22.04 is the current long term support release, maintained until 2025-04.
# Note: We need to use 22.10+, as 22.04 has `cmake@3.22.1` available only,
#       however, we need to use `cmake@3.23+`. Another option is to build it
#       from sources, which would increase the MTConnect Agent build time.
FROM ubuntu:22.10 AS os

# tzinfo hangs without this
ARG DEBIAN_FRONTEND=noninteractive

# ---------------------------------------------------------------------
# build
# ---------------------------------------------------------------------

FROM os AS build

# update os and add dependencies
# note: Dockerfiles run as root by default, so don't need sudo
RUN apt-get clean \
  && apt-get update \
  && apt-get install -y \
    autoconf \
    automake \
    build-essential \
    cmake \
    g++-11 \
    gcc-11 \
    git \
    python3 \
    python3-pip \
    rake \
    ruby \
  && pip install conan

# make an agent directory and cd into it
WORKDIR /root/agent

# bring in the repo contents, minus .dockerignore files
COPY . .

# set some variables
ENV PATH=$HOME/venv3.9/bin:$PATH
# Note: When using `conan/profiles/docker` profile, the build errors out at `[env]`.
ENV CONAN_PROFILE=conan/profiles/gcc
# TODO: I think we should hardcode `SHARED` value.
ENV SHARED=False
# TODO: Do we need these two variables? They have a default value (even `SHARED` is set to a default value). We might want to remove options with default values.
ENV WITH_RUBY=True
ENV WITH_TESTS=False

# limit cpus so don't run out of memory on local machine
# symptom: get error - "c++: fatal error: Killed signal terminated program cc1plus"
# can turn off if building in cloud
# Note: I have build this image on a machine 12-core CPU, 48 GB of RAM, therefore the build time for ARM64 was nearly the as the build time for AMD64 (ARM64 was slower by 2 minutes in the first `conan` command). Of course, it can be reverted to `1`, maybe to `2`, as we build two images for two archs.
ENV CONAN_CPU_COUNT=10

# make installer
# FIXME: Before commiting, run these two commands in one `RUN`.
RUN conan profile detect -f
# compile source (~20mins - 4hrs for qemu)
# TODO: What should be the `shared` value? In GitLab CI, it is set to `${{ matrix.shared }}` and `matrix.shared` to `["True", "False"]`.
RUN conan build . \
  --build=missing \
  -pr "$CONAN_PROFILE" \
  -o cpack=True \
  -o "shared=$SHARED" \
  -o with_docs=False \
  -o without_ipv6=False

# ---------------------------------------------------------------------
# release
# ---------------------------------------------------------------------

FROM os AS release

LABEL author="mtconnect" description="Docker image for the latest Production MTConnect C++ Agent"

# install ruby for simulator
RUN apt-get update && apt-get install -y ruby

# change to a new non-root user for better security.
# this also adds the user to a group with the same name.
# --create-home creates a home folder, ie /home/<username>
RUN useradd --create-home agent
USER agent

# install agent executable
COPY --chown=agent:agent --from=build /root/agent/build/static-*/Release/agent/agent /usr/local/bin

# copy data to /etc/mtconnect
COPY --chown=agent:agent --from=build /root/agent/schemas /etc/mtconnect/schemas
COPY --chown=agent:agent --from=build /root/agent/simulator /etc/mtconnect/simulator
COPY --chown=agent:agent --from=build /root/agent/styles /etc/mtconnect/styles

# expose port
EXPOSE 5000

WORKDIR /home/agent

# default command - can override with docker run or docker-compose command.
# this runs the adapter simulator and the agent using the sample config file.
# note: must use shell form here instead of exec form, since we're running
# multiple statements using shell commands (& and &&).
# see https://stackoverflow.com/questions/46797348/docker-cmd-exec-form-for-multiple-command-execution
# TODO: There is no `mtcagent` available. Was it renamed to `agent`?
CMD /usr/bin/ruby /etc/mtconnect/simulator/run_scenario.rb -l \
  /etc/mtconnect/simulator/VMC-3Axis-Log.txt & \
  cd /etc/mtconnect/simulator && agent run agent.cfg

# ---------------------------------------------------------------------
# note
# ---------------------------------------------------------------------

# after setup, the dirs look like this -
#
# /usr/local/bin
#  |-- agent - the cppagent application
#
# /etc/mtconnect
#  |-- schemas - xsd files
#  |-- simulator - agent.cfg, simulator.rb, vmc-3axis.xml, log.txt
#  |-- styles - styles.xsl, styles.css, favicon.ico, etc
#
# /home/agent - the user's directory

And here’s the script using which I have built the image (OFC, I didn’t push the image anywhere, therefore I have actually used docker_build_options='--no-cache --load'). It could serve as the basis for building the images via GitLab CI.

MTConnect Agent build script
#!/usr/bin/env bash

# Build a multi-arch Docker image of Production MTConnect C++ Agent and optionally publish it to Docker Hub


# Configure BASH to exit on failure
set -e

# Set path where we should clone the MTConnect repository
# Note: It should be either an empty folder or a non-existing folder
#       with an existing parent folder.
repo_path="$HOME/cppagent"

# Docker hub credentials
docker_username=''
docker_password=''

# MTConnect agent version to use
# Note: It should be an existing tag in the Git repository. In general, it should be any commit-like string
#   (branch name, commit hash, tag).
mtc_agent_version='v2.2.0.3'

# Define Docker builder name
builder_name='mtc_builder'

# Define image name
image_name='mtconnect/agent'

# Define the platform targets
platforms=('linux/amd64' 'linux/arm64')

# Define additional `docker buildx build` options
# Note: One could replace `--push` with `--load` in order to build local image only.
docker_build_options='--no-cache --push'

# Run QEMU hypervisor in a Docker container which enables execution of different multi-architecture
#   containers by QEMU 1 and `binfmt_misc`
# Note: This step will execute the registering scripts.
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

# Remove builder if it exists
docker buildx rm "$builder_name" || true

# Create new builder
docker buildx create --name "$builder_name" --driver docker-container --use

# Inspect the current builder instance
docker buildx inspect --bootstrap

# Clone MTConnect agent repository
if [ -d "$repo_path" ] && [ -d "$repo_path/.git" ]; do
  # When the repository exists, update it
  # FIXME: git reset --hard && gco "$mtc_agent_version"
  git -C "$repo_path" reset --hard
  git -C "$repo_path" checkout "$mtc_agent_version"
else
  # When the folder is empty or it does not exist or it is not a repository,
  #   remove it (just to be sure) and clone the repository
  rm -rf "$repo_path"
  git clone https://github.com/mtconnect/cppagent.git -b "$mtc_agent_version" "$repo_path"
fi

# Log into Docker Hub
docker login -u "$docker_username" --password-stdin <<< "$docker_password"
unset docker_username
unset docker_password

# Build a multi-arch Docker image of MTConnect agent for Linux/AMD64 and Linux/ARM64 platforms,
#   and (based on the `$push` variable) it them to Docker Hub
# Note: `$docker_build_options` needs to be unquoted, otherwise when it is set to an empty string,
#   `docker buildx build` errors out with `ERROR: "docker buildx build" requires exactly 1 argument.`
#   (this is a BASH feature, as a quoted empty string evaluates to a defined argument).
docker buildx build \
  -f "$repo_path/Dockerfile" \
  --platform "$(IFS=,; echo "${platforms[*]}")" \
  -t "$image_name:${mtc_agent_version//v/}" \
  -t "$image_name:latest" \
  $docker_build_options \
  "$repo_path"

# Log out from Docker Hub
docker logout

# [optional] Remove the MTConnect agent repo
rm -rf "$repo_path"

Update

At the request of @MRIIOT, I have push the image built from Dockerfile to ladder99/agent at Docker Hub.

I have not worked on the docker build file yet. I was working on the GitHub workflow to transition to actions. This was next once I resolved all the CI/CD issues.

We should also do the CD directly to docker hub once we have everything working.

Best, W

On Aug 2, 2023, at 21:45, Otto Bolyós @.***> wrote:

@wsobel https://github.com/wsobel, oh, so you actually upgrade the conan dep to v2? So the issue might lay in here https://github.com/mtconnect/cppagent/blob/v2.2.0.3/Dockerfile#L44 (you specifically install @.*** in the Docker build files). I think someone forgot to update the Docker build files before the v2…0.3 release.

— Reply to this email directly, view it on GitHub https://github.com/mtconnect/cppagent/issues/300#issuecomment-1662875685, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJ6BCKDBE5GHBLJN42JSVTXTKU6NANCNFSM6AAAAAA3BXXKNE. You are receiving this because you were mentioned.