Skip to content

skibum1869/Alpine_MTConnect_Agent

Repository files navigation

Docker Publish

MTConnnect_Alpine_Docker_Agent Project

This repo houses a Docker-Compose version of the MTConnect Cpp agent. This creates most of the needed items to build a local docker CPP agent using docker and docker-compose. This project will mirror the log file to the local machine for full trace logging of the agent. This project was origionally forked from RaymondCui21/MTConnect_Docker, The project has been seperated from the origional code set due to the amount of changes occuring. Then this project was origionally a branch of the debian based release skibum1869/MTConnect_Docker which was fully forked to generate a full release code set.

Build from Github source

To run the project clone a local instance of the repo.

git clone https://github.com/skibum1869/Alpine_MTConnect_Agent.git <name you want for the local repo>

Edit the agent.cfg to meet your requirements and add any devices you need to the folder. This has been tested using subfolders for devises and Assets. To add asset definitions to the compiled project include the following line under the devises line see below.

# ---- Release ----
### Create folders, copy device files and dependencies for the release
FROM alpine-base AS alpine-release
LABEL author="skibum1869" description="Alpine based docker image for the latest Release Version of the MTConnect C++ Agent"
EXPOSE 5000:5000/tcp
RUN apk add --no-cache \
  libstdc++ \
  libc6-compat

WORKDIR /MTC_Agent
# COPY <src> <dest>
COPY agent.cfg docker-entrypoint.sh /MTC_Agent/
COPY ./Devices/ /MTC_Agent/devices
COPY ./Assets/ /MTC_Agent/assets
COPY --from=alpine-core app_build/schemas/ /MTC_Agent/schemas
COPY --from=alpine-core app_build/simulator/ /MTC_Agent/simulator
COPY --from=alpine-core app_build/styles/ /MTC_Agent/styles
COPY --from=alpine-core app_build/agent/agent /MTC_Agent/

# Set permission on the folder
RUN chmod +x /MTC_Agent/agent && \
  chmod +x /MTC_Agent/docker-entrypoint.sh

ENTRYPOINT ["/bin/sh", "-x", "./docker-entrypoint.sh"]
### EOF

docker-entrypoint.sh:

#!/bin/sh
# Run file to call the agent
/lib/ld-musl-x86_64.so.1 --library-path lib /MTC_Agent/agent agent.cfg

To edit the instance settings use the docker-compose.yml file.

version: '3.5'
services:
  web:
    build: .
    environment:
      - TZ=Etc/UTC
    ports: 
      - target: 5000
        published: 5000
        protocol: tcp
        mode: host
    entrypoint: "/bin/sh -x ./docker-entrypoint.sh"
    working_dir: "/MTC_Agent"
    container_name: Alpine_MTConnect_Agent
    restart: unless-stopped
    volumes:
      - type: bind
        source: ./log/adapter.log
        target: /MTC_Agent/adapter.log
        consistency: delegated

Running from DockerHub

Running a project form the prebuilt dockerhub libarary will speed up the build time.

To get the project running create a dockerfile, docker-entrypoint.sh, and a docker-compose.yml file similar to the ones below.

To edit the instance settings use the docker-compose.yml file.

version: '3.5'
services:
  agent:
    container_name: MTConnect_Agent
    image: skibum1869/mtconnect_alpine_agent:latest
    environment:
      - TZ=Etc/UTC
    ports: 
      - target: 5000
        published: 5000
        protocol: tcp
        mode: host
    entrypoint: "/bin/sh -x ./docker-entrypoint.sh"
    working_dir: "/MTC_Agent"
    restart: unless-stopped
    volumes:
      - type: bind
        source: ./log/adapter.log
        target: /MTC_Agent/adapter.log
        consistency: delegated
      - './agent.cfg:/MTC_Agent/agent.cfg'
      - './mtconnect-devicefiles/Devices/:/MTC_Agent/devices'
      - './mtconnect-devicefiles/Assets/:/MTC_Agent/assets'

Core Docker and MTConnect Commands

Build comand for docker to create a run time for latest MTC_Agent

docker build . -t "mtc_agent:latest"

Run the docker image

docker run --name agent --rm -it mtc_agent

Clear all images and containers

docker system prune -a

Git pull latest and ignore local changes

git reset --hard | sudo git pull

To run the docker-compose file:

docker-compose up --force-recreate --build --remove-orphans -d

To shutdown the docker-compose instance

docker-compose down

Access the log files

From the pwd type the following:

grep (what are you searching for) log/adapter.log

Pushing Assets

To push the asset you need to be in the source folder of the asset.

curl -d @ZWEQ063C34HPII.xml 'http://example.com:5000/assets/ZWEQ063C34HPII.1?device=HEMsaw&type=CuttingTool'

Note: depending on the setup of your computer you may have to run the sudo command on a linux machine to get docker-compose to build or destroy a process.

About

This project is a docker and docker-compose instance of the latest MTconnect C++ Adapter. This fork is designed to run on alpine's latest version.

Topics

Resources

Stars

Watchers

Forks