<commit_before># MTConnect C++ Agent Docker image build instructions

# ---------------------------------------------------------------------
# notes
# ---------------------------------------------------------------------

# if building this with a private repo (eg cppagent_dev), need to pass
# in a github access token in order to clone the repo. 
#
# to build locally and push to docker hub, run this with something like -
#
#   docker buildx build \
#     --platform linux/amd64,linux/arm64 \
#     --tag ladder99/agent2 \
#     --secret id=access_token,src=ACCESS_TOKEN \
#     --push \
#     .
#
# ACCESS_TOKEN is a file containing a GitHub personal access token,
# so can clone the private mtconnect cppagent_dev repo.
# keep it out of the github repo with .gitignore.
# this sets up a file with the contents accessible at /run/secrete/access_token.
# see https://vsupalov.com/docker-buildkit-features/
#
# to build in github actions, pass this into the docker/build-push-action@v2 step -
#
#   secrets: "access_token=${{ secrets.ACCESS_TOKEN }}"
#
# then use access token as below with
#
#   RUN --mount=type=secret,id=access_token \
#     git clone https://$(cat /run/secrets/access_token)@github.com...
#
# then should be able to run with something like
#
#   docker run -it -p5001:5000 --name agent2 --rm ladder99/agent2:latest
#
# and visit http://localhost:5001 to see demo output

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

# base image - ubuntu has linux/amd64, linux/arm64 etc
FROM ubuntu:latest AS os

# tzinfo hangs without this
ARG DEBIAN_FRONTEND=noninteractive

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

FROM os AS build

# update os and add dependencies
# this follows recommended Docker practices -
# see https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run
# note: Dockerfiles run as root by default, so don't need sudo
RUN apt-get clean \
  && apt-get update \
  && apt-get install -y \
  build-essential python3.9 python3-pip git cmake make ruby rake \
  && pip install conan

# get latest source code
# could use `git checkout foo` to get a specific version here
RUN --mount=type=secret,id=access_token \
  cd ~ \
  && git clone --recurse-submodules --progress --depth 1 \
  https://$(cat /run/secrets/access_token)@github.com/mtconnect/cppagent_dev.git agent

# set some variables
ENV PATH=$HOME/venv3.9/bin:$PATH
ENV CONAN_PROFILE=conan/profiles/docker
ENV WITH_RUBY=True

# make installer
RUN cd ~/agent \
  && conan export conan/mqtt_cpp \
  && conan export conan/mruby \
  && conan install . -if build --build=missing \
  -pr $CONAN_PROFILE \
  -o run_tests=False \
  -o with_ruby=$WITH_RUBY

# 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

# compile source (~20mins - 4hrs for qemu)
RUN cd ~/agent && conan build . -bf build

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

FROM os AS release

LABEL author="mtconnect" description="Docker image for the latest Development MTConnect C++ Agent"
<commit_msg>try cpu count above install<commit_after># MTConnect C++ Agent Docker image build instructions

# ---------------------------------------------------------------------
# notes
# ---------------------------------------------------------------------

# if building this with a private repo (eg cppagent_dev), need to pass
# in a github access token in order to clone the repo. 
#
# to build locally and push to docker hub, run this with something like -
#
#   docker buildx build \
#     --platform linux/amd64,linux/arm64 \
#     --tag ladder99/agent2 \
#     --secret id=access_token,src=ACCESS_TOKEN \
#     --push \
#     .
#
# ACCESS_TOKEN is a file containing a GitHub personal access token,
# so can clone the private mtconnect cppagent_dev repo.
# keep it out of the github repo with .gitignore.
# this sets up a file with the contents accessible at /run/secrete/access_token.
# see https://vsupalov.com/docker-buildkit-features/
#
# to build in github actions, pass this into the docker/build-push-action@v2 step -
#
#   secrets: "access_token=${{ secrets.ACCESS_TOKEN }}"
#
# then use access token as below with
#
#   RUN --mount=type=secret,id=access_token \
#     git clone https://$(cat /run/secrets/access_token)@github.com...
#
# then should be able to run with something like
#
#   docker run -it -p5001:5000 --name agent2 --rm ladder99/agent2:latest
#
# and visit http://localhost:5001 to see demo output

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

# base image - ubuntu has linux/amd64, linux/arm64 etc
FROM ubuntu:latest AS os

# tzinfo hangs without this
ARG DEBIAN_FRONTEND=noninteractive

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

FROM os AS build

# update os and add dependencies
# this follows recommended Docker practices -
# see https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run
# note: Dockerfiles run as root by default, so don't need sudo
RUN apt-get clean \
  && apt-get update \
  && apt-get install -y \
  build-essential python3.9 python3-pip git cmake make ruby rake \
  && pip install conan

# get latest source code
# could use `git checkout foo` to get a specific version here
RUN --mount=type=secret,id=access_token \
  cd ~ \
  && git clone --recurse-submodules --progress --depth 1 \
  https://$(cat /run/secrets/access_token)@github.com/mtconnect/cppagent_dev.git agent

# set some variables
ENV PATH=$HOME/venv3.9/bin:$PATH
ENV CONAN_PROFILE=conan/profiles/docker
ENV WITH_RUBY=True

# 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

# make installer
RUN cd ~/agent \
  && conan export conan/mqtt_cpp \
  && conan export conan/mruby \
  && conan install . -if build --build=missing \
  -pr $CONAN_PROFILE \
  -o run_tests=False \
  -o with_ruby=$WITH_RUBY

# compile source (~20mins - 4hrs for qemu)
RUN cd ~/agent && conan build . -bf build

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

FROM os AS release

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

{'fraction_non_alphanumeric': 0.24659123875834058, 'fraction_numerical': 0.011314186248912098, 'mean_word_length': 1.8885630498533725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1134749', 'n_tokens_mistral': 1979, 'n_tokens_neox': 1870, 'n_words': 662}