2023년 3월 13일 월요일

[Docker] docker build RUN apk update Error

Step 3/7 : RUN apk update

 ---> Running in 2fdba320b542

fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz

fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz

ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.9/main: temporary error (try again later)

WARNING: Ignoring APKINDEX.b89edf6e.tar.gz: No such file or directory

ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.9/community: temporary error (try again later)

WARNING: Ignoring APKINDEX.737f7e01.tar.gz: No such file or directory



$ docker build --tag shlee/springboot-cicd:latest --no-cache --network=host .

 --> Add "--network=host" .. 


[업데이트 2026-10]

  • 컨테이너 안에서 apk 인덱스를 받아오지 못해서 나는 오류다. 빌드하는 동안 컨테이너 네트워크(DNS 포함)가 막혀 있을 때 자주 나고, --network=host를 주면 호스트 네트워크를 그대로 써서 해결되는 경우가 많다.
  • 예제의 Alpine v3.9는 오래된 버전이라 저장소 주소가 더 이상 응답하지 않을 수 있다. 베이스 이미지를 최신 Alpine 태그로 올려서 다시 빌드해 보는 것도 방법이다.

2023년 3월 10일 금요일

Nexus Installation on Ubuntu

$ mkdir nexus

$ wget https://download.sonatype.com/nexus/3/nexus-3.39.0-01-unix.tar.gz

$ sudo apt-get update

$ sudo apt install openjdk-8-jdk-headless

$ cd nexus/bin


- install & startup : nexus run

- startup : nexus start

- stop : nexus stop



[업데이트 2026-10]

  • 위의 3.39.0 + JDK 8 조합은 오래된 구성이다. 최신 버전은 Sonatype 다운로드 페이지에서 확인하고, 필요한 Java 버전은 받은 버전의 요구사항을 따른다. 최근 배포본에는 JDK가 같이 들어 있는 경우가 있어서 따로 설치하지 않아도 될 수 있다.
  • root가 아닌 별도 사용자(예: nexus)로 실행하는 것이 좋다.
  • 기동하면 기본 접속 주소는 http://localhost:8081 이다.
  • 초기 admin 비밀번호는 sonatype-work/nexus3/admin.password 파일에 들어 있다. 처음 로그인한 뒤 바꿔준다.

SonarQube Installation ( on Ubuntu )

 $ sudo apt update




$ sudo apt -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common


$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -






$ wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.8.0.63668.zip


$ unzip sonarqube-9.8.0.63668.zip


$ sudo groupadd sonar


$ sudo useradd -c "SonarQube - User" -d /home/shlee/sonarqube/ -g sonar sonar


# $ sudo chown -R sonar:sonar /home/shlee/sonarqube/


$ sudo chown -R shlee:shlee /home/shlee/sonarqube/




$ /home/shlee/sonarqube/bin/linux-x86-64/sonar.sh start


$ /home/shlee/sonarqube/bin/linux-x86-64/sonar.sh stop




$ curl localhost:9000 [admin/admin and change password]




[SonarQube Setup in gitlab / SonarQube]


1) create gitlab Impersonation Token in Gitlab


2) create gitlab project and insert gitlab Token in sonarqube 


3) create credential for "admin" account in sonarqube 


   and copy credential, paste to jenkins new credentials






[SonarQube Setup In jenkins]


Install GitLab plugin for Jenkins - version 1.5.13 or later


Install SonarQube Scanner plugin for Jenkins - version 2.11 or later




setting for integrating cicd


setting for sonarqube server 




[Jenkinsfile]


  withSonarQubeEnv('sonarqube_rookie01') {


                sh "mvn clean verify sonar:sonar -Dsonar.projectKey=<프로젝트 키>"


              }




sonarqube_rookie01 <- ID for sonarQube Server Setting


<프로젝트 키> <-- project key in sonarqube


-----




(1) Docker Push in Jenkinsfile


 docker.withRegistry('<Docker Registry URL>', '<Credential defined in Jenkins Credentials>') {


     dockerImage.push('<Tag>')


 }




ex>


 docker.withRegistry('http://localhost:7890/repository/docker-local-registry/', 'docker_credential') {


      dockerImage.push('latest')


 }




(2) Integrate Sonar with Jenkins


 withSonarQubeEnv('<Name of Jenkins SonarQube Server Settings>') {


      sh "mvn clean verify <Goal for SonarQube (default :  'sonar:sonar' )> -Dsonar.projectKey=<ProjectKey generated by SonarQube Server>"


 }


[업데이트 2026-10]

  • SonarQube 9.8은 오래된 버전이다. 현재 Community Build는 Java 17 또는 21이 필요하고, 압축을 푸는 디렉터리 이름이 숫자로 시작하면 안 된다.
  • 첫 로그인은 admin/admin이고, 로그인하면 바로 비밀번호를 바꿔준다.
  • 맨 위의 Docker apt 키 등록 명령은 SonarQube 설치와 직접 관련이 없어 보인다. 복사하다 섞인 것 같으니 따라 하지 않아도 된다.
  • 스캐너(SonarScanner)의 Java 요구 버전도 올라가고 있다. 2026년 7월부터 Community Build용 스캐너는 Java 21만 지원하고, JRE 자동 프로비저닝이 켜져 있으면 따로 신경 쓰지 않아도 된다.
  • 프로젝트 키는 노출을 피하려고 <프로젝트 키>로 바꿔 두었다.

Prometheus & Grafana Installation (on Ubuntu)

 [Prometheus]


1) download prometheus

$ wget <https://prometheus.io/download/ 에서 OS에 맞는 파일의 주소>

압축 해제.. & prometheus.yml 편집

scrape_configs:

  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.

  - job_name: "prometheus"


    # metrics_path defaults to '/metrics'

    # scheme defaults to 'http'.

    static_configs:

      - targets: ["localhost:9091"]

      - 

  - job_name: "springboot"

    scrape_interval: 15s

    metrics_path: "/actuator/prometheus"

    static_configs:

      - targets: ["rookie01.local:8080"]

      - 

2) startup

$ ./prometheus --config.file=prometheus.yml  --web.listen-address="0.0.0.0:9091" --web.enable-lifecycle 2>&1 | tee -a ./startup.log &



3) shutdown

$ curl -X POST localhost:9091/-/quit   ( or kill )


4) brower 접속

http://localhost:9091

http://localhost:9091/metrics



[Grafana]

1) download installation file

$ wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.3.6.linux-amd64.tar.gz


2) startup

$ ./bin/grafana-server web


3) browser 접속

http://localhost:3000  ( admin / admin ; 첫 로그인 후 비밀번호 변경)


4) springboot 용 pannel 샘플 다운로드 / Import

 download from : https://grafana.com/grafana/dashboards/12900-springboot-apm-dashboard/


[업데이트 2026-10]

  • Prometheus 다운로드 명령이 Alpine 저장소 주소로 잘못 들어가 있었다(복사 실수). Prometheus 공식 다운로드 페이지(https://prometheus.io/download/)에서 OS에 맞는 파일을 받는 것으로 고쳤다.
  • Grafana 9.3.6도 오래된 버전이라 새로 설치한다면 Grafana 공식 다운로드 페이지에서 최신 버전을 확인한다.
  • Grafana 기본 계정은 admin/admin이고, 첫 로그인 후 비밀번호를 바꾸면 된다. 글에 적혀 있던 비밀번호 힌트는 지웠다.