AdaptiveConsulting / nexus-casc-plugin

Configuration as code plugin for Sonatype Nexus Repository Manager
MIT License
48 stars 21 forks source link

Dockerfile to Build Custom Nexus Image, with Plugin #35

Closed prom3theu5 closed 2 years ago

prom3theu5 commented 2 years ago

Not sure where you'd want it - but this produces a custom docker image with the plugin installed - its multistage, so the final image doesn't include maven, or the source etc, just nexus and the plugin

ARG SONATYPE_IMAGE=sonatype/nexus3:3.39.0

FROM openjdk:8-jdk-alpine as BUILDER

ARG MAVEN_VERSION=3.6.3        
ARG USER_HOME_DIR="/root"
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
ARG NEXUS_CAC_PLUGIN_REPO=https://github.com/AdaptiveConsulting/nexus-casc-plugin
ARG NEXUS_CAC_PLUGIN_VERSION=3.39.0-01
ARG NEXUS_CAC_PLUGIN_ARTIFACT_NAME=nexus-casc-plugin.kar

RUN apk add --no-cache curl tar bash procps git

RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
  && echo "Downloading maven" \
  && curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
  \
  && echo "Unziping maven" \
  && tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
  \
  && echo "Cleaning and setting links" \
  && rm -f /tmp/apache-maven.tar.gz \
  && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn

ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"

RUN mkdir -p /artifacts /git \
  && echo "Downloading Nexus Configuration As Code Source Code" \
  && cd /git \
  && git clone $NEXUS_CAC_PLUGIN_REPO \
  && cd nexus-casc-plugin \
  \
  && echo "Building Nexus CaC Plugin" \
  && mvn package \
  && mv ./target/nexus-casc-plugin-${NEXUS_CAC_PLUGIN_VERSION}-bundle.kar /artifacts/$NEXUS_CAC_PLUGIN_ARTIFACT_NAME \
  && echo "DONE!"  

FROM $SONATYPE_IMAGE
COPY --from=BUILDER /artifacts/$NEXUS_CAC_PLUGIN_ARTIFACT_NAME /opt/sonatype/nexus/deploy/
bdellegrazie commented 2 years ago

@prom3theu5 thank you - @sergei-ivanov added it and integrated it.

prom3theu5 commented 2 years ago

Awesome cheers! - you're welcome Wasn't sure how you'd want to integrate, so rather than make decision for you, left it up to you :)