Argo - Continuous Delivery for Production
Prerequisites
🛑 Stop: make sure your pipeline is green before setting up ArgoCD
The QA folder in the Gitops repo will already have been created for you by the Tekton pipeline.
Setup
Use the following instructions to set up a new continuous delivery controller using ArgoCD.
Create the project
-
Determine the name of the new project.
- For react-intro:
react-intro-<USER ID>-prod
(for examplereact-intro-35-prod
) - For squads:
squad-<squad-number>-prod
(for examplesquad-4-prod
)
- For react-intro:
-
Create the project with
oc new-project react-intro-<USER ID>-prod
(for exampleoc new-project react-intro-35-prod
)
By creating the project, you will have permissions to manually edit objects in that project (like Deployments).
Create the production folder in the GitOps repository
- Run
oc console
to open the web console. - Click the "9 box" menu, then select "Git Ops", then copy the http link.
- Clone the gitops repo:
cd ~ git clone <repo url> cd gitops code .
- Find the application you want to deploy under the
/qa
folder, and copy that entire folder to the new<environment>
foldermkdir -p production cp -r qa/react-intro-<user-number> production/
- Git add, commit, and push to your branch.
git add -A git commit -m "added production env" git pull git push
Add ArgoCD App
- Run
oc console
to open the web console. - On the OpenShift console page, Click the "9 box" menu, then select "ArgoCD"
- Accept the security warnings (easiest in Chrome)
- Login
- if "Login via OpenShift" is available, do that
- if not, run
igc credentials
to get the password
- Click "New App"
- Fill in the form
- General
- Application name:
react-intro-<user-number>-prod
orsquad-<squad-number>-prod
- Project = default
- Application name:
- Sync Policy = automatic
- Check PRUNE RESOURCES and SELF HEAL
- Check "use a schema to validate resource manifests"
- General
- Source
- Repository = url to gitops repository ("9 box" menu, click "Git Ops")
- Revision = HEAD
- Path = path to the project environment folder you just created.
- For react-intro
<environment>/react-intro-<user-number>/react-intro
- For projects
<environment>/squad-<squad-number>/<repo-name>
- For react-intro
- Destination
- cluster = select the one available option
- namespace = the target namespace. Should be the same as "Application name" above
- Click create at the top
Add the image pull policy
Now the ArgoCD app is displayed. Shortly you will notice that the pod creation failed, and it has a status of ImagePullBackOff
.
This is because the new namespace is trying to pull images created in another namespace.
To solve this problem:
-
Give the new environment permission to pull images from dev namespace
oc policy add-role-to-group system:image-puller system:serviceaccounts:<new-project-name> -n <dev-project-name>
For example:
oc policy add-role-to-group system:image-puller system:serviceaccounts:react-intro-<user number>-prod -n react-intro-<user number>-dev
If successful, you will see something like the following:
Warning: Group 'system:serviceaccounts:react-intro-<user number>-prod' not found clusterrole.rbac.authorization.k8s.io/system:image-puller added: "system:serviceaccounts:<new-project-name>"
-
Click the menu on the right side of the pod in ArgoCD then select "delete". OpenShift will immediately create a new pod and this time it will have permission to pull images from the other namespace.
-
If successful, you will see something like the following when you open the ArgoCD controller (Note: every heart is green):
What just happened?
You have a new Production environment.
Your CI/CD pipeline now looks like the following sequence diagram:
Click here to view/edit the diagram
Promoting a new version to production
- Make a change to the application (for example changing the text in the
App.js
component) - Wait for the Tekton pipeline to go green
- Update GitOps repository
cd ~/gitops git pull
- In the QA folder (which was automatically updated by Tekton) find the latest app version
- Update the version in the
production/<project>/<app-repo-name>/requirements.yaml
file to match QA - Commit and push
git add -A git commit -m "bump production version" git push
- Open the ArgoCD app and note the new version is running in production.