FROM alpine:3.15

# Create a non-root user with UID 1001
RUN addgroup -S -g 1001 db-agent && \
    adduser -S -u 1001 -G db-agent db-agent

# Install JRE needed to run the agent
RUN apk add openjdk11-jre

# Install AppDynamics Database Agent
ENV DB_AGENT_HOME /opt/appdynamics/db-agent
RUN mkdir -p ${DB_AGENT_HOME}
ADD . ${DB_AGENT_HOME}

RUN chmod 755 ${DB_AGENT_HOME}/start-dbagent-dockerfile-entrypoint.sh

# Changing ownership of the DB_AGENT_HOME directory to the non-root user
RUN chown -R 1001:1001 ${DB_AGENT_HOME}

# Switch to the non-root  user
USER 1001

# Changing directory to DB_AGENT_HOME
WORKDIR ${DB_AGENT_HOME}

# Configure and Run AppDynamics Database Agent
CMD ["./start-dbagent-dockerfile-entrypoint.sh"]