Skip to content

Instantly share code, notes, and snippets.

@jovemfelix
Last active January 26, 2022 10:27
Show Gist options
  • Save jovemfelix/8ad27f47c4831b272280551df0538a64 to your computer and use it in GitHub Desktop.
Save jovemfelix/8ad27f47c4831b272280551df0538a64 to your computer and use it in GitHub Desktop.

get-nexus-bundle.sh

#!/bin/bash
if curl -L --progress-bar -O https://download.sonatype.com/nexus/oss/nexus-2.14.3-02-bundle.tar.gz
then
  echo "Nexus bundle download successful"
else
  echo "Download failed"
fi

nexus-start.sh

#!/bin/bash
CONTEXT_PATH="/nexus"
MAX_HEAP="768m"
MIN_HEAP="256m"
JAVA_OPTS="-server -Djava.net.preferIPv4Stack=true"
LAUNCHER_CONF="./conf/jetty.xml ./conf/jetty-requestlog.xml"
SONATYPE_WORK="${NEXUS_HOME}/sonatype-work"
cd ${NEXUS_HOME}/nexus2
exec java \
  -Dnexus-work=${SONATYPE_WORK} \
  -Dnexus-webapp-context-path=${CONTEXT_PATH} \
  -Xms${MIN_HEAP} -Xmx${MAX_HEAP} \
  -cp 'conf/:lib/*' \
  ${JAVA_OPTS} \
  org.sonatype.nexus.bootstrap.Launcher ${LAUNCHER_CONF}

Dockerfile

FROM registry.access.redhat.com/ubi8/ubi:8.5
MAINTAINER jovemfelix < [email protected] >
ARG NEXUS_VERSION=2.14.3-02
ARG user=nexus
ARG group=nexus
ARG uid=1001
ARG gid=1001
ARG bundle=nexus-2.14.3-02-bundle.tar.gz
ARG script=nexus-start.sh
ARG v1=/opt/nexus/sonatype-work
ENV NEXUS_HOME=/opt/nexus
ENV SCRIPT=${script}

RUN yum install -y --setopt=tsflags=nodocs java-1.8.0-openjdk-devel && \
    yum clean all -y && \
    groupadd -r ${group} -f -g ${gid} && \
    useradd -u ${uid} -r -g ${group} -m -d ${NEXUS_HOME} \
        -s /sbin/nologin \
        -c "Nexus User" ${user}

ADD ${bundle} ${NEXUS_HOME}
COPY ${script} ${NEXUS_HOME}

RUN ln -s ${NEXUS_HOME}/nexus-${NEXUS_VERSION} ${NEXUS_HOME}/nexus2 && \
    chown -R ${user}:${group} ${NEXUS_HOME} && \
    chmod -R 755 ${NEXUS_HOME}

USER ${user}
VOLUME [${v1}]

WORKDIR ${NEXUS_HOME}

CMD ["sh", "-c", "${NEXUS_HOME}/${SCRIPT}"]

Commands

Build

podman build --layers=false -t nexus .

Validate Inside Image locally

podman run -it -v /tmp/docker/work:/opt/nexus/sonatype-work -p 127.0.0.1:18081:8081 --entrypoint /bin/bash nexus

Start local

#!/bin/bash
if [ ! -d /tmp/docker/work ]; then
  mkdir -p /tmp/docker/work
  chcon -Rt container_file_t /tmp/docker/work
  podman unshare chown 1001:1001 /tmp/docker/work
fi

podman run -it -v /tmp/docker/work:/opt/nexus/sonatype-work -p 127.0.0.1:18081:8081 --entrypoint /bin/bash nexus

Tag + Push to Quay

podman tag localhost/nexus:latest quay.io/jovemfelix/nexus:2.14.3-02

podman login quay.io
podman push quay.io/jovemfelix/nexus:2.14.3-02

Run on Openshift

oc login -u XXX -p XXX API_URL

Deployment file

apiVersion: v1
items:
- apiVersion: v1
  kind: Service
  metadata:
    labels:
      app: nexus
    name: nexus
  spec:
    ports:
    - name: nexus
      port: 8081
    selector:
      name: nexus
- apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    labels:
      app: nexus
    name: nexus
  spec:
    accessModes:
    - ReadWriteOnce
    resources:
      requests:
        storage: 1Gi
- apiVersion: apps/v1
  kind: Deployment
  metadata:
    labels:
      app: nexus
    name: nexus
  spec:
    replicas: 1
    selector:
      matchLabels:
        name: nexus
    strategy:
      type: Recreate
    template:
      metadata:
        labels:
          name: nexus
      spec:
        containers:
        - env: []
          image: quay.io/jovemfelix/nexus:2.14.3-02 
          imagePullPolicy: Always
          livenessProbe:
            failureThreshold: 10
            initialDelaySeconds: 30
            tcpSocket:
              port: 8081
            timeoutSeconds: 1
          name: nexus
          ports:
          - containerPort: 8081
          readinessProbe:
            exec:
              command:
              - /bin/sh
              - -i
              - -c
              - curl 127.0.0.1:8081
            initialDelaySeconds: 5
            timeoutSeconds: 1
          resources:
            limits:
              memory: 512Mi
          volumeMounts:
          - mountPath: /opt/nexus/sonatype-work
            name: nexus-data
        volumes:
        - name: nexus-data
          persistentVolumeClaim:
            claimName: nexus
    triggers:
    - type: ConfigChange
kind: List
metadata: {}

deploy it

oc create -f nexus-deployment.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment