thesuhu

Gitlab CI/CD

Sep 25th, 2020 (edited)
155
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 1. Create file .gitlab-ci.yml
  2. # 2. Setting -> CI/CD -> General pipelines, uncheck Skip outdated deployment jobs
  3. # 3. Setting -> CI/CD -> Runners, klik Disable shared runner
  4. # 4. Setting -> CI/CD -> Variables, tambahkan variable sesuai tanda $ yang ada di file .gitlab-ci.yml
  5.     # NPA_PASSWORD = token dari user profile -> Personal Access Tokens -> create token (isi nama dan centang)
  6.     # NPA_USERNAME = username gitlab
  7.     # Registry = registry.gitlab.com
  8.     # RunDev = whoami
  9.     # RunProd = wget -O /dev/null --post-data 'key=value' http://10.242.xxx.xx:port/api/webhooks/b844 ... dst
  10.     # RunStag = whoami
  11.     # Tagging = registry.gitlab.com/.../.../nama-repo
  12. # 5. Setting -> CI/CD -> Cleanup policy for tags, pilih disabled jika dipertahankan, enable jika otomatis hapus
  13. # 6. Install runner sendiri agar tidak dibatasi waktu di gitlab:
  14.     # create volume config
  15.     docker volume create gitlab-runner-config
  16.     # start runner
  17.     docker run -d --name gitlab-runner --restart always \
  18.         -v /var/run/docker.sock:/var/run/docker.sock \
  19.         -v gitlab-runner-config:/etc/gitlab-runner \
  20.         gitlab/gitlab-runner:latest
  21. # 7. Register gitlab runner
  22. docker run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner:latest register
  23.     # pastikan di project sudah ada file .gitlab-ci.yml
  24.     # enter gitlab ci coordinator -> https://gitlab.com/ (lihat di gitlab -> Setting -> CI/CD -> Runner -> Set up a specific Runner manually)
  25.     # enter gitlab token -> sAV6UhXsXXXXybRr_ (lihat di gitlab -> Setting -> CI/CD -> Runner -> Set up a specific Runner manually)
  26.     # enter gitlab runner description -> bebas
  27.     # enter gitlab runner tag -> bebas
  28.     # Provide the runner executor. For most use cases, enter docker -> docker
  29.     # If you entered docker as your executor, you’ll be asked for the default image to be used for projects that do not define one in .gitlab-ci.yml
  30. # 8. connect bash container gitlab-runner, tambahkan volume di file /etc/gitlab-runner/config.toml pada bagian volume
  31.     # volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
  32. cd /etc/gitlab-runner
  33. apt update
  34. apt install nano
  35. nano config.toml
  36. # 9. Di gitlab -> Setting -> CI/CD -> runner -> pilih runner yg jalan, klik edit, centang -> Run untagged jobs
  37. # 10. Deploy awal dengan membuat service, image dari registry.gitlab.com
  38. # 11. Di docker portaniner service, lihat detil service, klik webhook, copy alamat webhook, paste di variable RunProd (wget -O /dev/null --post-data 'key=value' http:// ... dst)
  39.  
RAW Paste Data