Sonatype Nexus Repository Kurulum/Konfigürasyonu
Kurulum yaptığım makineye ait sistem konfigürasyon bilgileri;

1-Update System Packages
sudo apt-get update
2- Install OpenJDK 1.8 on Ubuntu 20.04 LTS
sudo apt install openjdk-8-jre-headless
3-Download Nexus Repository Manager setup on Ubuntu 20.04 LTS
cd /opt sudo wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz

4-Install Nexus Repository on Ubuntu 20.04 LTS
sudo tar -zxvf latest-unix.tar.gz

Rename the extracted Nexus setup folder to nexus
sudo mv /opt/nexus-3.54.1-01 /opt/nexus
Nexus root user ile çalıştırmamak için nexus adında bir user oluşturuyoruz.
sudo adduser nexus
Nexus kullanıcısı için parola ayarlamak için visudo açıyoruz. Ve aşağıdaki kodu yazıyoruz.
nexus ALL=(ALL) NOPASSWD: ALL

Nexus kullanıcısına, dizinine, ve dosyalarına yetki veriyoruz.
sudo chown -R nexus:nexus /opt/nexus sudo chown -R nexus:nexus /opt/sonatype-work
Nexus’un boot açılışında servis olarak başlaması için aşağıdaki dosyada # işaretini kaldırıyoruz. /opt/nexus/bin/nexus.rc
run_as_user="nexus"

5-Run Nexus as a service using Systemd
Nexus systemd servisi olarak çalıştırmak için aşağıdaki dizine kodları ekliyoruz.
sudo nano /etc/systemd/system/nexus.service
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Restart=on-abort
[Install]
WantedBy=multi-user.target

Nexus servisini başlatıyoruz.
sudo systemctl start nexus
Nexus servisini başlangıçta otomatik başlayacak şekilde ayarlıyoruz.
sudo systemctl enable nexus
Servisi kontrol ediyoruz
sudo systemctl status nexus

6- Access Nexus Repository Web Interface
Firewall kullanıyorsanız aşağıdaki komut çalıştırmalısınız.
ufw allow 8081/tcp
Uygulamamıza erişiyoruz
http://server_IP:8081

Sign in tıkladıktan sonra username password isteyecektir. Aşağıdaki komut ile öğrenebilirsiniz.
sudo cat /opt/sonatype-work/nexus3/admin.password


Kurulum tamamlandı.
7-Docker Repository Oluşturulması
Genel olarak nexus repository port atamamız aşağıdaki gibi olacak.
“nexusrepo1.eastus.cloudapp.azure.com:8081” < Nexus
“nexusrepo1.eastus.cloudapp.azure.com:8082” <Docker Hub Registry
“nexusrepo1.eastus.cloudapp.azure.com:8083” <Docker Registry
-Setting > Repositories > Create Repository > Docker Hosted

–Aşağıdaki alanları dolduruyoruz.
Create Repository diyoruz.

-Repository oluşturduktan sonra Security > Realms > Active Realms menüsünde Docker Bearer Token sağ tarafa Active kısma kaydırıyoruz.

8-Upload Docker Image My Repository
-Docker kurulu bir makine üzerinde dockerfile build edip oluşturduğumuz image nexus repository’e push’layacağız.
Öncelikle kendi repomuza ait url veya ip bilgilerini docker kurulu makine üzerinde aşağıdaki dizine insecure-registries olarak tanıtmamız gerekiyor.sudo vi /etc/docker/daemon.json

{
"insecure-registries": [
"nexusrepo1.eastus.cloudapp.azure.com:8081",
"nexusrepo1.eastus.cloudapp.azure.com:8082",
"nexusrepo1.eastus.cloudapp.azure.com:8083"
]
}
-Değişikliği tamamladıktan sonra aşağıdaki komut ile docker daemon restart ediyoruz.sudo systemctl restart docker
-Önce docker login -u admin http://nexusrepo1.eastus.cloudapp.azure.com:8083
komutu ile login oluyoruz.

-Örnek bir projeyi github’dan download ediyoruz.
https://bitbucket.org/ananthkannan/mydockerrepo cd mydockerrepo/pythonApp

-Builddocker build . -t nexusrepo1.eastus.cloudapp.azure.com:8083/dockerrepo
-Pushdocker push nexusrepo1.eastus.cloudapp.azure.com:8083/dockerrepo
–Verify

-Docker Tag Kullanımı
docker tag 4993d1d61cae nexusrepo1.eastus.cloudapp.azure.com:8083/dockerrepo:61
docker push nexusrepo1.eastus.cloudapp.azure.com:8083/dockerrepo:61

-Docker Runsudo docker run -p 8081:5000 --rm --name myfirstApp1 your_docker_user_id/myphythonapp
