DevOps LINUX : Docker + GitLab + Jenkins (Auto Deploy Production) - ARTIKEL SALIM TEKNOLOGI

Latest

Artikel Bermanfaat Untuk Kita Semua

Minggu, 30 April 2023

DevOps LINUX : Docker + GitLab + Jenkins (Auto Deploy Production)

 



Server : 

- Install Openjdk 11 Headless (apt install openjdk-11-jdk-headless)

- Install Jenkins (see: https://www.jenkins.io/doc/book/installing/linux/

open ->  ipadresss:8080



cmd : cat /var/lib/jenkins/secrets/initialAdminPassword

- Install Nginx (configuration ip address jenkins to domain name)

config path : nano /etc/nginx/sites-available/default

server {
server_name jenkins.xxg.co.id;

location / {
proxy_pass http://localhost:8080;
proxy_read_timeout 90s;
}
}

- Install Docker

- Login account, use cmd :  docker login registry.gitlab.com (see : https://docs.gitlab.com/ee/user/packages/container_registry/authenticate_with_container_registry.html)

** warning : you dont install docker-compose before login registry gitlab!

- Test create TASK on jenkins

see example picture below

configure source (GIT)

if you have add account, click add -> jenkins.

you dont change2 combo box, default value is good

after that, select your account


check list on build trigger, token value is dummy (free text)


set in curl gitlab.ci.yml :

curl --user admin:$JENKINS_PWD http://domain.jenkins.com:8080/job/dotnet-mvc/build?token=tokenbebasaja



JENKINS_PWD : password account jenkins

JENKINS_REPO : is token dummy (free text)




build command : 

sudo docker login registry.gitlab.com -u salimsea -p glpatx-_U-YSY_pcdJ2TjCC9PWz

sudo docker pull registry.gitlab.com/salimsea/dotnet-mvc-demo:latest

sudo docker remove -f dotnet-mvc

sudo docker run -dt -p 5000:5000 --rm --name dotnet-mvc registry.gitlab.com/salimsea/dotnet-mvc-demo:latest

**info -> -p glpatx-_U-YSY_pcdJ2TjCC9PWz : personal token (edit profile) (check all rules)


- check permission PASWD jenkins(visudo nopasswd)


cmd : jenkins ALL=(ALL) NOPASSWD: ALL


- check this .gitlab-ci.yml 



- if you want use webhook gitlab

go to sertting -> manage user


configure -> API token (save this token)


go to gitlab project


URL : http://admin:119b7ab4012054072b92c5a8f62fddaa830@jenkinsx.xxxg.co.id:8080/job/dotnet-mvc/build?token=tokenbebasaja
**info -> admin:<generate token user>


- dockerfile publish dotnet 5.0


==========

tutor deploy use two branch

1. primary branch use main or master

2. create new branch for production (cmd : git branch -m production)

3. git checkout production -> git pull origin main -> git push origin production

==========


refrence : 

https://faun.pub/building-a-docker-image-with-gitlab-ci-and-net-core-8f59681a86c4

https://docs.gitlab.com/ee/user/packages/container_registry/authenticate_with_container_registry.html

https://www.youtube.com/watch?v=P4pKnbcVRb8&t=380s

https://www.youtube.com/watch?v=T1Y-tr081EE







Tidak ada komentar:

Posting Komentar