log-viewer icon indicating copy to clipboard operation
log-viewer copied to clipboard

Cretae a docker image and make it available in docker hub

Open kovax opened this issue 3 years ago • 11 comments

I use docker-compose to setup applications, and it would be great if I could use logviewer as an independent container. I would be happy to help to setup this feature.

The pom.xml example bellow is from my open source project showing how to use google jib plugin: https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin

Apps running in a docker container only have access to the files of the host system through shared volumes. This means that browse-and-select log files feature will not work. Instead the logviewer should scan a specific directory (e.g. /app/externalLogs/) and expose this to the hosts (see <volumes> section). When I build my docker-compose project I configure my apps to share the logs with the hosts in a single directory, which means I can configure logviewer container to access that single directory through its shared volume.

          <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>jib-maven-plugin</artifactId>
            <configuration>
              <from>
                <image>openjdk:8</image>
              </from>
              <to>
                <image>cristalise/development:${revision}</image>
              </to>
              <container>
                <creationTime>${maven.build.timestamp}</creationTime>
                <environment>
                  <APP_NAME>${project.artifactId}</APP_NAME>
                </environment>
                <jvmFlags>
                  <jvmFlag>-Dlogback.configurationFile=/app/config/logback.xml</jvmFlag>
                  <jvmFlag>-DAPP_NAME=${project.artifactId}</jvmFlag>
                  <jvmFlag>-Xms1024m</jvmFlag>
                  <jvmFlag>-Xdebug</jvmFlag>
                </jvmFlags>
                <mainClass>org.cristalise.kernel.process.StandardServer</mainClass>
                <args>
                  <arg>-config</arg>
                  <arg>/app/config/server.conf</arg>
                  <arg>-connect</arg>
                  <arg>/app/config/local.clc</arg>
                  <arg>-Shiro.iniFile</arg>
                  <arg>/app/config/shiro.ini</arg>
                </args>
                <ports>
                  <port>7000</port>
                </ports>
                <volumes>
                  <volume>/app/config</volume>
                  <volume>/app/log</volume>
                </volumes>
              </container>
            </configuration>
          </plugin>

kovax avatar Dec 27 '21 10:12 kovax

@sevdokimov it would be great to know if you support this proposal. I can do all the changes to the poms, but as I stated above some changes to the file selection would be needed that I am not qualified to do unfortunately.

kovax avatar Jan 23 '22 17:01 kovax

@kovax , Thank you. I definitely support this proposal. It's a good idea. But, unfortunately, I'm not familiar with Docker. How can I get the list of volumes from java code? Or how we can pass the list of volumes to the application configuration? Sorry for the delay.

sevdokimov avatar Jan 31 '22 11:01 sevdokimov

@sevdokimov sorry for the long slience. I can definitely do all the docker changes.

How can I get the list of volumes from java code?

You cannot do that, an application in a docker container only sees the volumes (i.e. files, directories) shared from the host. That is what I tried to explain in my original post. So instead it shall be possible to configure the logviewer to scan a specific directory only instead of leting the user the select one. This is the change I would need you to do.

Or how we can pass the list of volumes to the application configuration?

I plan to use Google JIB to build the docker image, which puts the full application into /app directory (see JIB FAQ: Where is the application in the container). So following this approach, the logviewer image shall expose the /app/externalLogs directory as a volume.

kovax avatar Feb 21 '22 15:02 kovax

I agree with kovax. Its good idea. But dockers cant communicate in docker-compose and look files each other. But maybe u can use configuration in docker-compose like this: log-viewer: image: log-viewer networks: core_net: ipv4_address: 172.19.1.1 restart: always volumes: - /app/all-logs-yours-apps:/opt/logs/ - /app/log-viewer.conf:/log-viewer-1.0.3/config.conf

And in your confg file: logs = [ { path: "/opt/logs/**" } ]

mxgreen29 avatar Sep 20 '22 11:09 mxgreen29

With volume mapping, you could make a docker container where people would map their logs into the docker container for the log viewer to see. Similar to the suggestion above - I think you could craft a docker image with this app that worked, using env variables probably

nklisch avatar Nov 14 '22 02:11 nklisch

There is no need for additional development @sevdokimov, I created a Dockerfile and a docker compose file that packages the software and lets them pass in their own config file, and passes in relevant logs: Steps:

  1. Download a release
  2. cd into the release's folder
  3. Create the following Dockerfile into this folder:
# Select a image that includes java 8
FROM openjdk:8-slim-buster # this is the base image 
# Copy files from log-viewer release
COPY ./lib /lib
COPY ./logviewer.sh /
# expose the port the the service will run on
EXPOSE 8111
# command that is executed when the docker container starts
CMD ["/logviewer.sh"]

Then create the following docker-compose file in the same directory as before

version: "3"
services:
  log-viewer: 
    image: sevdokimov/log-viewer
    build: # This builds the image - if this image was placed on Docker Hub, you could remove this and use the username/image:tag to pull the pre-built image
      context: .
      dockerfile: Dockerfile
    configs:
      - config.conf # This passes the config defined below into the container - this is mandatory as we do not copy in the default config
    volumes:
      - /var/log:/var/log # This can be modified to pass in whatever log directories into the container. The right side is the path inside the docker container and should match your config file
    ports:
      - 8111:8111 # This can be remapped to whatever port you would like to expose on the left. The right, with the above dockerfile, must remain 8111
configs:
  config.conf: # This must be this name as it is passed in as that file name
    file: ./config.conf # This is the path to the config file for this log-viewer docker container

Then run: $ docker compose up -d --build

Or if there ends up being a docker hub image run: $ docker compose up -d

nklisch avatar Nov 14 '22 02:11 nklisch