OpenShift with GitLab Lab Documentation
OpenShift Demo Documentation:
-
Build Demo Environment -
Document Demo -
Test Document
Build OpenShift / Gitlab Demo:
Note: This is very CPU and memory intensive. It is recommended that you close as many apps as possible to conserve resources for this.
- Download the OpenShift CRC image:
- Create a Red Hat account (if you don't have one) using your GitLab email address: https://www.redhat.com/wapps/ugc/register.html?_flowId=register-flow&_flowExecutionKey=e1s1
- Go to: https://console.redhat.com/openshift/create/local
- In the "Downloads" section, download the macOS x86_64 CodeReady Container
- In the "Pull Secret" section, hit the "Download pull secret" button and save that file with the CodeReady Container.
- Once downloaded run the crc-macos-amd64.pkg file to install, accept all defaults. When complete, press "Close".
- Open a terminal and run $
crc delete
(to verify that no CRC images already exist) IMPORTANT - If this command fails with a "cannot verify" error message, open System Preferences and go to "Security & Privacy", on the "General" tab, click the "Allow Anyway" button to the right of "crc was blocked.....". Then go back to your terminal and run thecrc delete
again. - Run $
crc setup
When asked “Would you like to contribute anonymous usage statistics?” Just answer "N". - Once you see “Your system is correctly setup for using CodeReady Containers”, run $
crc start
- You'll be asked for the Pull Secret, copy the pull secret from the file you saved earlier and paste it into the terminal. Once you've given it the pull secret the process takes a while, so go get some coffee.
- If you get a warning like “Is '/Applications/CodeReady Containers.app' running?” that means you may already have the CRC app installed. Go into your apps and start the app called “CodeReady Containers” then run
crc start
again.
- When the start process completes:
You'll see a “Started the OpenShift cluster.” message. Below that, find the line that says “Log in as administrator:” Copy and paste the password noted there into a doc or something to save, you'll need it later. Run
- $
eval $(crc oc-env)
- $
- Run the next two lines:
- $
oc login -u developer -p developer https://api.crc.testing:6443
- $
oc login -u kubeadmin -p <USE PASSWORD NOTED IN STEP 6> https://api.crc.testing:6443
- $
- Run $
crc console
- If all is right, this command will open web browser and automatically surf to your new OpenShift instance.
- Accept any certificate errors as needed.
- To login you will use the username kubeadmin and the password that was noted in step 6.
- If the OpenShift page fails to open, start by checking your /etc/hosts file on your Mac.
- Run $
crc ip
(to get IP address) - Run $
ping console-openshift-console.apps-crc.testing
and verify and has the same IP address.
-
This completes the OpenShift CRC install. Congrats! Other handy commands:
- Run $
crc console --credentials
(if you've lost the admin credentials) - Run $
crc stop
(to stop the vm) - Run $
crc status
(to see if its running or not) - Run $
crc version
(to check for latest version) - Run $
crc delete
(if you'd like to delete the VM from your machine) NOTE: The CRC Openshift image is just a trial to kick the tires of Openshift. Had this been an actual install, you'd have FAR more to do.
- Run $
Install the GitLab Runner Operator
- Assure that your CRC environment is running by executing: $
crc status
- Open a browser and surf to: https://console-openshift-console.apps-crc.testing/dashboards
- First, we'll create a workspace to place our app. In the left pane select "Administration" then "Namespaces"
- Click "Create Namespace" and in the name field type "gitlab-express-dev" and hit "Create". After the namespace is created, click "Namespaces" in the left pane.
- Now we'll install the GitLab Runner Operator. In the left pane, click "Operators" then "Operator Hub". If the page loads with an error, click "Try again"
- Once the Operator Hub pages loads, click the dropdown arrow next to "Project:" and select "gitlab-express-dev" if its not already.
- In the "Filter by keyword" field search for the operator named "GitLab" and click on it.
- Review the information on the GitLab Operator page and then click "Install" in the upper left.
- On the "Install Operator" page, leave the defaults and click "Install".
- You will see the Operator be installed. Once the Status states "Succeeded" its complete. Note: You may need to refresh the page to update status.
Attach to GitLab Project
- Open a new browser tab, go to your workspace at: https://gitlab-core.us.gitlabdemo.cloud
- Click on "New Project", then "Import project", then "Repo by URL".
- Under "Git repository URL" enter: https://gitlab.com/praumann/tanukitech-openshift.git
- Name your project, be sure the slug is filled in too.
- Select "Public" or "Internal" for visibility then click "Create Project"
- Once the project has been created, click on "Settings" then "CI/CD" then click "Expand" to the right of "Variables"
- Create a variable with a key of "OC_URL" and a value of "https://api.crc.testing:6443" (don't add the quotes)
- Create a variable with a key of "OC_NAMESPACESLUG" and a value of "gitlab-express" (don't add the quotes)
- Create a variable with a key of "OC_TOKEN" and to get the value:
- Go into the Red Hat Console
- In upper right corner click on "kube:admin" then "Copy Login Command".
- A new tab should open, click "Display Token"
- Grab the token underneath "Your API token is" and use that for the OC_TOKEN value.
- Now click on "Expand" in the "Runners" section above "Variables".
- We're going to be standing up a Specific Runner a bit later, for now under "Shared Runners" click the "Disable shared Runners" button.
- At this time under "Set up a specific Runner manually" section, make note of the URL and token. We'll need that for the next step.
- From your Mac terminal: $ oc project gitlab-express-dev Use the following command with your runner token (from previous step) at the end: $ oc create secret generic gitlab-runner-secret --from-literal runner_registration_token=
- Next we will create the CRD file. Run $ nano gitlab-runner.yml and then paste the text from this file and save file: https://gitlab.com/us-public-sector/cs/channel-success-projects/-/blob/master/gitlab-runner.yml
- Now lets apply that CRD file by running the command: $ oc apply -f gitlab-runner.yml
- In the OpenShift console click on Workloads > Pods and set the "Project" dropdown to gitlab-express-dev, you'll see the gitlab-runner pod being spun up.
- Once complete (in a "Running" state) your new runner will appear in your project Settings > CI/CD > Runners page under "Runners activated for this project". You may need to refresh the page.
- Wait until you have a green circle next to your new runner. Once its green click on the edit icon next to the runner name.
- In the description field, lets give it a new name of "ocp-runner-".
- Also, check the box next to "Indicates whether this runner can pick jobs without tags" and then "Save changes".
- At this point we are ready to try deploying our app to OpenShift via the runner installed in Openshift.
- Back in the Openshift console, click the dropdown button next to "Adminstrator" in the top of the left pane. Switch to "Developer"
- Click "Topology" in the left pane and assure the "Project:" namespace is set to "gitlab-express-dev" and "Application" is set to "all applications". This is what you have built so far. Lets deploy the app now.
- In the GitLab interface go to CI/CD > Pipelines and then click "Run Pipeline".
- Click "Run Pipeline" again. If all goes well, the pipeline should stop at Deploy, go ahead and allow it to deploy. For now, if the Deploy job fails, it should still be ok, move on.
- Once the pipeline is complete, in the Openshift console go to "Topology" and assure the "Project:" namespace is set to "gitlab-express-dev" and "Application" is set to "all applications". You should now see a "openshift-test-app" pod. Click on it.
- A panel should open from the right, underneath "Routes" click on the URL under "Location".
- If it opens a "Welcome to Express" screen, congrats, you're now a GitLab/Openshift pro... :-)
To reset and start over:
- $
crc stop
- $
crc delete
- $
rm -r ~/.crc
- In GitLab Openshift project, delete runner you created.
- Delete the GitLab Openshift project you created.
Then start from step #4 above.
To delete the CodeReady Container application & containers from your mac:
- Perform steps 1-5 above (under "To reset and startover:")
- On your desktop click Go > Applications, highlight the "CodeReady Container" application, right click, click "Move to Trash".
- If app does not delete and says that it is still open:
- Open "Activity Monitor"
- Find and highlight the CodeReady Container process.
- Click the stop button (a button with X on a stop sign) in the top of the Activity Monitor window.
- When process disappears, repeat step #2 (closed).
To see the demo live, watch this video: https://drive.google.com/file/d/1xofVb1igoE-DjrtiiSXzlzVhCcOcOjx7/view?usp=sharing
Edited by Pete Raumann