[컴] nexus 로 private repository 사용해보기

 넥서스 / maven repository 만들기

 

작성중...

nexus 로 private repository 사용해보기

실행

  1. docker-compose.yml 다운로드
  2. docker compose up
  3. web browser 에서 http://localhost:8081/nexus/ 로 접근하면 nexus repository 화면이 보인다.
    • http://localhost:8081/nexus/ 우측상단에 login 을 할 수 있다.
    • admin 기본 암호 : admin /admin123

$SONATYPE_WORK

SONATYPE_WORK(nexsus-data 로 보면 된다) 는 처음에 비어있어도 된다. nexus server 를 실행하면, SONATYPE_WORK에 많은 directory 들이 생긴다.

이곳의 storage 부분에 maven repository 관련 내용들이 저장된다.

docker 내용

주요내용은 nexus dockerfile 을 보면 된다. 하는 일은 다음과 같다.

  1. nexus, openjdk 다운로드
  2. 새로운 user 추가
  3. nexus 실행

docker-compose.yml

docker-compose.yml 은 ref.1 에서 volume 부분만 수정했다.

version: "3"

services:
  nexus:
    image: sonatype/nexus
    volumes:
      - "./nexus-data:/sonatype-work"
      # - "nexus-data:/sonatype-work"
    ports:
      - "8081:8081"
  
# volumes:
#   nexus-data: {}

sonatype/nexus

  • https://github.com/sonatype/docker-nexus/blob/master/oss/Dockerfile
FROM registry.access.redhat.com/ubi7/ubi

LABEL vendor=Sonatype \
  maintainer="Sonatype <cloud-ops@sonatype.com>" \
  com.sonatype.license="Apache License, Version 2.0" \
  com.sonatype.name="Nexus Repository Manager OSS base image"

ARG NEXUS_VERSION=2.14.20-02
ARG NEXUS_DOWNLOAD_URL=https://download.sonatype.com/nexus/oss/nexus-${NEXUS_VERSION}-bundle.tar.gz

ENV SONATYPE_WORK=/sonatype-work
ENV NEXUS_HOME=/opt/sonatype/nexus

RUN yum install -v -y --disableplugin=subscription-manager hostname java-1.8.0-openjdk-headless \
  && yum-config-manager --add-repo http://mirror.centos.org/centos/7/os/x86_64/ \
  && rpm --import http://mirror.centos.org/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 \
  && yum install -v -y createrepo \
  && yum --disableplugin=subscription-manager clean all

RUN mkdir -p ${NEXUS_HOME} && \
  curl --fail --silent --location --retry 3 ${NEXUS_DOWNLOAD_URL} | \
  tar xz -C /tmp nexus-${NEXUS_VERSION} && \
  mv /tmp/nexus-${NEXUS_VERSION}/* ${NEXUS_HOME}/ && \
  rm -rf /tmp/nexus-${NEXUS_VERSION}

RUN useradd -r -u 200 -m -c "nexus role account" -d ${SONATYPE_WORK} -s /bin/false nexus

VOLUME ${SONATYPE_WORK}

EXPOSE 8081
WORKDIR ${NEXUS_HOME}
USER nexus

ENV CONTEXT_PATH /nexus
ENV MAX_HEAP 768m
ENV MIN_HEAP 256m
ENV JAVA_OPTS -server -Djava.net.preferIPv4Stack=true
ENV LAUNCHER_CONF ./conf/jetty.xml ./conf/jetty-requestlog.xml

CMD 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}

간단한 test

  • sample-android-gradle.zip : project의 build.gradle 의 repository 를 localhost로 변경했다.

gradlew.bat build(linux 라면 아마 gradle build) 를 하면 build 가 된다. 이 때 우리가 방금 띄운 nexus maven repository 에서 필요한 package 들을 가져가게 된다.

gradlew.bat build --debug --no-build-cache
D:\a\prog\kotlin\SampleApp_sa>gradlew.bat build --no-build-cache

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'SampleApp'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:7.0.2.
     Searched in the following locations:
       - http://localhost:8081/content/groups/public/com/android/tools/build/gradle/7.0.2/gradle-7.0.2.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project :
   > Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30.
     Searched in the following locations:
       - http://localhost:8081/content/groups/public/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.30/kotlin-gradle-plugin-1.5.30.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project :

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 636ms

D:\a\prog\kotlin\SampleApp_sa>

See Also

  1. 사설 Repository Nexus 설치 / 연동 - 가리사니
  2. Managing Repositories

Reference

  1. GitHub - sonatype/docker-nexus: Docker image for Sonatype Nexus

댓글 없음:

댓글 쓰기