Initializing latest and stable¶
review branches are deployed by the GitLab CI/CD pipeline, and latest and stable workloads are deployed by Flux. This section describes how to initialize a project for latest and stable deployments.
Create and store a project access token¶
Note: This step requires admin access
Create your own personal access token¶
-
On gitlab, go to
User Settings>Access Tokens -
Create a new personal access token with these permissions:
api,write_repository,write_registry,admin_mode -
Store your token as it will only show once!
Create dependabot token¶
-
Use the curl command below to create a dependabot token. You need
jqinstalled for this.INSERT_PERSONAL_ACCESS_TOKEN_HEREis your personal access token from aboveINSERT_APP_NAME_HEREis the name of your appINSERT_PROJECT_ID_HEREis the gitlab repo project idresponse=$(curl --request POST \ --header "PRIVATE-TOKEN: INSERT_PERSONAL_ACCESS_TOKEN_HERE" \ --header "Content-Type: application/json" \ --data '{ "name": "INSERT_APP_NAME_HERE-dependabot", "scopes": ["api", "write_repository", "write_registry"], "expires_at": "2024-07-01" }' \ "https://issues.ltc.bcit.ca/api/v4/projects/INSERT_PROJECT_ID_HERE/access_tokens") reshaped_response=$(echo $response | jq -c '{ gitlab: ., password: .token, username: .name }') echo $reshaped_response
-
Copy the JSON returned by the command above
Store the tokens in Vault¶
- Go to https://vault.ltc.bcit.ca:8200/ui/vault/secrets/tokens/list and create a new secret with name
INSERT_APP_NAME_HERE-dependabotand use the JSON output before as the value.
Add app authorization config to Vault¶
Add your application to the vault-configuration repo.
-
Inside
vault-configuration/gitlab-jwt-authfolder, copy an existing app-dependabot.tffile and replace the project name andproject_idwith your app. -
Inside
vault-configuration/kubernetes-authfolder, copy an existing app-kubeauthbot.tffile and replace the project name app.
Add application to Flux Config¶
Add your application to flux-config repo
-
Copy an existing app folder inside
flux-config/appand replace all with your app name. -
Add your app to
flux-config/app/kustomization.yaml
Setup GitLab webhooks¶
Add Flux webhooks to your GitLab project so that Flux can receive notifications when changes are made to the project.
Latest Webhook¶
-
Go to Rancher
-
Choose
prod-3(latest) >More Resources>notification.toolkit.fluxcd.io>Receivers- Find your app receiver and copy the hook path:
/hook/random-hash
- Find your app receiver and copy the hook path:
-
Choose
prod-3(latest) >Storage>Secrets- Find your app webhook and copy the token
-
-
Create a new webhook either from gitlab project repo or CURL command
-
From gitlab project repo, go to
Settings>Webhooks- URL:
https://latest--flux-config.ltc.bcit.ca/hook/INSERT_HOOK_RECEIVER_HASH - Secret token:
INSERT_TOKEN_FROM_STORAGE_SECRETS_WEBHOOK - Trigger:
Push events,Tag push events,Deployment events - Enable SSL verification
- URL:
OR use a CURL command:
curl --request POST \ --header "PRIVATE-TOKEN: INSERT_PERSONAL_ACCESS_TOKEN_HERE" \ --header "Content-Type: application/json" \ --data '{"url": "https://latest--flux-config.ltc.bcit.ca/hook/INSERT_HOOK_RECEIVER_HASH", "token": "INSERT_TOKEN_FROM_STORAGE_SECRETS_WEBHOOK", "push_events": true, "tag_push_events": true, "deployment_events": true}' \ "https://issues.ltc.bcit.ca/api/v4/projects/INSERT_PROJECT_ID_HERE/hooks" -
Stable Webhook¶
-
Go to Rancher
-
Choose
prod-2(stable) >More Resources>notification.toolkit.fluxcd.io>Receivers- Find your app receiver and copy the hook path:
/hook/random-hash
- Find your app receiver and copy the hook path:
-
Choose
prod-2(stable) >Storage>Secrets- Find your app webhook and copy the token
-
-
Create a new webhook either from gitlab project repo or CURL command
-
From gitlab project repo, go to
Settings>Webhooks- URL:
https://flux-config.ltc.bcit.ca/hook/INSERT_HOOK_RECEIVER_HASH - Secret token:
INSERT_TOKEN_FROM_STORAGE_SECRETS_WEBHOOK - Trigger:
Push events,Tag push events,Deployment events - Enable SSL verification
- URL:
OR use a CURL command:
curl --request POST \ --header "PRIVATE-TOKEN: INSERT_PERSONAL_ACCESS_TOKEN_HERE" \ --header "Content-Type: application/json" \ --data '{"url": "https://flux-config.ltc.bcit.ca/hook/INSERT_HOOK_RECEIVER_HASH", "token": "INSERT_TOKEN_FROM_STORAGE_SECRETS_WEBHOOK", "push_events": true, "tag_push_events": true, "deployment_events": true}' \ "https://issues.ltc.bcit.ca/api/v4/projects/INSERT_PROJECT_ID_HERE/hooks" -