diff --git a/2023-08-31-openshift-rails-workshop/README.org b/2023-08-31-openshift-rails-workshop/README.org index 99be8d7..22b9f2b 100644 --- a/2023-08-31-openshift-rails-workshop/README.org +++ b/2023-08-31-openshift-rails-workshop/README.org @@ -38,7 +38,7 @@ oc new-project bitbucket #+RESULTS: #+begin_example -Already on project "bitbucket" on server "https://api.rosa-7lpn7.2pqm.p1.openshiftapps.com:6443". +Now using project "bitbucket" on server "https://api.cluster-dkxhl.dkxhl.sandbox1652.opentlc.com:6443". You can add applications to this project with the 'new-app' command. For example, try: @@ -53,35 +53,72 @@ to build a new example application in Ruby. Or use kubectl to deploy a simple Ku Once the namespace is created we can deploy Bitbucket using the official Bitbucket image from Atlassian. #+begin_src bash :results output -oc --namespace bitbucket new-app --image docker.io/atlassian/bitbucket-server --name bitbucket +cat << EOF | oc --namespace bitbucket apply --filename - +kind: Deployment +apiVersion: apps/v1 +metadata: + name: bitbucket + namespace: bitbucket + labels: + app: bitbucket +spec: + replicas: 1 + selector: + matchLabels: + deployment: bitbucket + template: + metadata: + labels: + deployment: bitbucket + spec: + volumes: + - name: bitbucket-volume + emptyDir: {} + containers: + - name: bitbucket + image: docker.io/atlassian/bitbucket-server@sha256:30556d63fc935a1c3c9da41e6fff617e452ad7a52060a92b6a20f9179dd637a5 + ports: + - containerPort: 7990 + protocol: TCP + - containerPort: 7999 + protocol: TCP + resources: + limits: + cpu: 500m + memory: 4096Mi + volumeMounts: + - name: bitbucket-volume + mountPath: /var/atlassian/application-data/bitbucket + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + imagePullPolicy: IfNotPresent + restartPolicy: Always + terminationGracePeriodSeconds: 30 + dnsPolicy: ClusterFirst + securityContext: {} + schedulerName: default-scheduler + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 25% + maxSurge: 25% + revisionHistoryLimit: 10 + progressDeadlineSeconds: 600 +EOF #+end_src #+RESULTS: -#+begin_example ---> Found container image 525a6bc (3 days old) from docker.io for "docker.io/atlassian/bitbucket-server" - - ,* An image stream tag will be created as "bitbucket:latest" that will track this image - ---> Creating resources ... - imagestream.image.openshift.io "bitbucket" created - deployment.apps "bitbucket" created - service "bitbucket" created ---> Success - Application is not exposed. You can expose services to the outside world by executing one or more of the commands below: - 'oc expose service/bitbucket' - Run 'oc status' to view your app. -#+end_example +: deployment.apps/bitbucket created Now, let's verify that the Bitbucket pod started successfully. #+begin_src bash :results output oc --namespace bitbucket get pods - #+end_src #+RESULTS: : NAME READY STATUS RESTARTS AGE -: bitbucket-56d9849bbf-7922z 1/1 Running 0 2m36s +: bitbucket-74bc96b849-5nbvl 1/1 Running 0 45s As this is running successfully, let's expose it with a ~route~ so that we can access it from our web browser. @@ -92,12 +129,12 @@ oc --namespace bitbucket get route #+RESULTS: : route.route.openshift.io/bitbucket created -: NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD -: bitbucket bitbucket-bitbucket.apps.rosa-7lpn7.2pqm.p1.openshiftapps.com bitbucket 7990 edge None +: NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD +: bitbucket bitbucket-bitbucket.apps.cluster-dkxhl.dkxhl.sandbox1652.opentlc.com bitbucket 7990 edge None Once we open the Bitbucket route in our browser, we need to follow a short setup process manually before we can continue with the rest of our automation. - 1. Select your language ~English~. + 1. Select your language ~English (United States)~. 2. Select ~internal~ and click ~Next~. You'll then be prompted for an Atlassian license key. For the purposes of this workshop, we'll be generating a new trial license [[https://my.atlassian.com/license/evaluation][here]]. @@ -118,15 +155,14 @@ First step is to create additional users. #+begin_src bash :results none source .env bitbucket_route=$(oc get route --namespace bitbucket | awk '{print $2}' | tail -n 1) - for user in {1..30}; do echo curl --user "admin:${bitbucket_password}" \ --header "'Content-Type: application/json'" \ - --data "" - "\"https://${bitbucket_route}/rest/api/latest/admin/users?name=user${user}&displayName=user${user}&emailAddress=user${user}%40example.com&password=${bitbucket_user_password}\"" >> users.sh + --header "'X-Atlassian-Token: nocheck'" \ + --request "POST" \ + "\"https://${bitbucket_route}/rest/api/latest/admin/users?name=user${user}&displayName=user${user}&emailAddress=user${user}%40example.com&password=${bitbucket_user_password}\"" >> users.sh - cat users.sh done chmod +x users.sh && ./users.sh && rm users.sh #+end_src @@ -178,7 +214,7 @@ EOF #+end_src #+RESULTS: -: subscription.operators.coreos.com/openshift-pipelines-operator created +: subscription.operators.coreos.com/openshift-pipelines-operator configured * 5 - Install openshift web terminal operator @@ -241,4 +277,3 @@ EOF #+end_src #+RESULTS: -: knativeserving.operator.knative.dev/knative-serving created diff --git a/2023-08-31-openshift-rails-workshop/images/openshift-pipelines.gif b/2023-08-31-openshift-rails-workshop/images/openshift-pipelines.gif new file mode 100644 index 0000000..384947d Binary files /dev/null and b/2023-08-31-openshift-rails-workshop/images/openshift-pipelines.gif differ diff --git a/2023-08-31-openshift-rails-workshop/instructions.org b/2023-08-31-openshift-rails-workshop/instructions.org index 3f8f986..c984aa5 100644 --- a/2023-08-31-openshift-rails-workshop/instructions.org +++ b/2023-08-31-openshift-rails-workshop/instructions.org @@ -111,6 +111,14 @@ Want to quickly test a proof of concept or spin up a container? Awesome, within [[./images/add-application.png]] +** Visual pipeline builder + +OpenShift Pipelines (based on Tekton) make creating cloud native pipelines on OpenShift easy. There is a pipeline web interface built into the OpenShift web console so you don't need to login to another system and switch contexts to be able to interact with your pipelines. + +[[./images/openshift-pipelines.gif]] + + + * 3. Setting up your development environment For our first hands on excercise let's get logged into the tools we'll be using today and get familar with each. @@ -126,7 +134,7 @@ Use the credentials provided on the workshop etherpad to login. [[./images/bitbucket-login.png]] -Once logged in you should be able to view and create a fork of the ~Rails Team/openstreetmap-website~ repository to your own user using this link: [[https://bitbucket-bitbucket.apps.rosa-7lpn7.2pqm.p1.openshiftapps.com/projects/MSD/repos/openstreetmap-website?fork]] +Once logged in you should be able to view and create a fork of the ~Rails Team/rails-example~ repository to your own user using this link: [[https://bitbucket-bitbucket.apps.rosa-7lpn7.2pqm.p1.openshiftapps.com/projects/MSD/repos/rails-example?fork]] [[./images/bitbucket-fork.png]] @@ -139,4 +147,68 @@ Use the credentials provided on the workshop etherpad to login. [[./images/openshift-login.png]] -Once logged in feel free to repeat the OpenShift tour we went through as a group in section two to get more comfortable with the user interface. +Once logged in, feel free to repeat the OpenShift tour we went through as a group in section two to get more comfortable with the user interface. + + +* 4. Deploying a ruby application + +Now that we are logged into our environment let's move on to deplying the ~rails-example~ codebase we forked earlier, onto OpenShift. We'll do this in two different ways: + +** User the web interface to import from git and deploy + 1) Create a project bu clicking +Add > Create Project > Enter Project name (i.e. userXX) + 2) Click on the ~Import from Git~ tile in your add menu. + 3) Enter the repo-url for your repository fork. + 4) Click on the ~Ruby~ on Builder Image. + 5) Enter ~rails-example~ in Name field. + 6) Click create button and you will be redirected to ~Topology~ screen. + 7) Click on ~rails-example~ application to see check the progress of the build (this should take roughly 2 minutes). + 8) Click the route once the pod is ~Running~ + +** Using the command line to import from git deploy + +1) Click on the web terminal ~>_~ icon in the top right corner of the web console. +2) A terminal will pop up in the bottom of the window, this can sometimes take a minute or two to start. +3) Copy the following command into the termuinal and press ~Enter~. + + #+begin_src bash :results output +oc --namespace user1 new-app --name rails-cli centos/ruby-25-centos7~https://github.com/sclorg/ruby-ex.git + #+end_src + + #+RESULTS: + #+begin_example + --> Found container image e96bd99 (2 years old) from Docker Hub for "centos/ruby-25-centos7" + + Ruby 2.5 + -------- + Ruby 2.5 available as container is a base platform for building and running various Ruby 2.5 applications and frameworks. Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). It is simple, straight-forward, and extensible. + + Tags: builder, ruby, ruby25, rh-ruby25 + + ,* An image stream tag will be created as "ruby-25-centos7:latest" that will track the source image + ,* A source build using source code from https://github.com/sclorg/ruby-ex.git will be created + ,* The resulting image will be pushed to image stream tag "rails-cli:latest" + ,* Every time "ruby-25-centos7:latest" changes a new build will be triggered + + --> Creating resources ... + imagestream.image.openshift.io "ruby-25-centos7" created + imagestream.image.openshift.io "rails-cli" created + buildconfig.build.openshift.io "rails-cli" created + deployment.apps "rails-cli" created + service "rails-cli" created + --> Success + Build scheduled, use 'oc logs -f buildconfig/rails-cli' to track its progress. + Application is not exposed. You can expose services to the outside world by executing one or more of the commands below: + 'oc expose service/rails-cli' + Run 'oc status' to view your app. + #+end_example + + 4) Let's open the web console again and we should now see another application pod in our topology view! + 5) Click on the pod, and open the route to see the application serving traffic. + + +** Creating a tekton deployment pipeline for our app + +1) Click on "Pipelines" in the OpenShift web console developer view. +2) Click on ~Create~ > ~Pipeline~ in the top right hand corner. +3) Enter the name ~ruby-pipeline~. +4) Click on ~Add task~, and type in ~clone~, then select ~git-clone~ from Red Hat and click ~Add~.