001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.camel.common.processor;
007
008import org.apache.camel.Exchange;
009import org.apache.camel.Processor;
010
011import java.nio.file.Path;
012
013/**
014 * Processor for determining if the application is currently running in
015 * a Docker environment. Adds a header `CamelDockerRunning` of type boolean
016 * to the exchange headers.
017 *
018 * WARNING
019 * Checks for existence of /.dockerenv in the filesystem. Note that the presence
020 * of this file is not documented and that this check might not work in the future.
021 *
022 * See <a href="https://superuser.com/questions/1021834/what-are-dockerenv-and-dockerinit">...</a>
023 *
024 * @author Ralf Claussnitzer
025 */
026public class DockerRunningProcessor implements Processor {
027
028    public static final String DOCKER_RUNNING = "CamelDockerRunning";
029
030    @Override
031    public void process(final Exchange exchange) throws Exception {
032        final boolean dockerenvExists = Path.of("/.dockerenv").toFile().exists();
033        exchange.getMessage().setHeader(DOCKER_RUNNING, dockerenvExists);
034    }
035}