This is a sample project, using Ruby with Sinatra framework to create a simple Hello World web application. With OCI DevOps Service and this project, you'll be able to build this application and store the executable in Oracle Artifact Registry.
In this example, you'll build a simple Ruby web application, test it locally and push your built artifact to the OCI Artifact Registry using the OCI DevOps service.
The first step is to download the repository to your local workspace.
git clone git@github.com:yashj0209/buildspec_ruby_example.git
Open a terminal and test out the Ruby Hello World web app example.
- Download and install Ruby : https://www.ruby-lang.org/en/downloads/
- Verify Ruby is installed by :
ruby -v
- Navigate to project's root directory :
cd buildspec_ruby_example
- Install bundler :
gem install bundler
- Install other dependencies (listed in Gemfile):
bundle install
. This will generate Gemfile.lock - Run the application :
ruby app.rb
Now, confirm you can access the web app running in the browser by open your browser to http://0.0.0.0:9000/ or according to any other port specified in app.rb
Now that you've seen how you can locally test this app, let's build our CI/CD pipeline in OCI DevOps Service.
- Create a DevOps Project or use and an existing project.
- Create an External Connection to your Github repository in your DevOps project.
- Create a Personal Access Token (PAT): https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token
- In the OCI Console, Go to Identity & Security -> Vault and create a Vault in compartment of your own choice.
- Create a Master Key that will be used to encrypt the PATs.
- Select Secrets from under Resources and create a secret using PAT obtained from Github account.
- Make a note of the OCID of the secret.
- Now, go to the desired project and select External Connection from the resources.
- Select type as Github and provide OCID of the secret under Personal Access Token.
- Finally, allow Build Pipeline (dynamic group with DevOps Resources) to use PAT secret by writing a policy in the root compartment as:
Allow dynamic-group dg-with-devops-resources to manage secret-family in tenancy
Create a new Build Pipeline to build, test and deliver artifacts.
In your Build Pipeline, first add a Managed Build stage.
- The Build Spec File Path is the relative location in your repo of the build_spec.yml . Leave the default, for this example.
- For the Primary Code Repository
- Select connection type as Github
- Select external connection you created above
- Give the repo URL to the repo which contains build_spec.yml file.
- Select main branch.
Create an Artifact Registry to store executable ruby file from Managed Build stage.
- Go to Artifact Registry in OCI Console and click on Create Repository
- You can name the artifact repo:
ruby-sinatra-example-repo
In the project, under Artifacts, create a DevOps Artifact to point to the Artifact repository location you just created above. Enter the information for the Artifact location:
- Name: Ruby-Sinatra-File
- Type: General Artifact
- Artifact Source : Artifact Registry repository
- Select Artifact registry repository as the one created in previous steps
- Artifact location: Choose set Custom location and provide path and version
- Replace parameters: Yes, substitute placeholders
Required policies must be added in the root compartment for the Artifact Registry and DevOps Artifact resource.
- Provide access to Artifact registry to deliver artifacts :
Allow dynamic-group dg-with-devops-resources to manage generic-artifacts in tenancy
- Provide access to read deploy artifacts in deliver artifact stage :
Allow dynamic-group dg-with-devops-resources to manage devops-family in tenancy
Let's add a Deliver Artifacts stage to your Build Pipeline to deliver the Ruby-Sinatra-File
artifact to the Artifact Registry.
The Deliver Artifacts stage maps the output Artifacts from the Managed Build stage to deliver to the Artifact Registry through a DevOps Artifact resource.
Add a Deliver Artifacts stage to your Build Pipeline after the Managed Build stage. To configure this stage:
- In your Deliver Artifacts stage, choose
Select Artifact
- From the list of artifacts select the
Ruby-Sinatra-File
artifact that you created above
- Assign the outputArtifact from the
build_spec.yml
to the DevOps project artifact. For the "Build config/result Artifact name" enter:OUTPUT
(This name should be the same as the one mentioned in the outputArtifact section of the build_spec.yml file).
Use the Manual Run button to start a Build Run
Manual Run will use the Primary Code Repository, will start the Build Pipeline, first running the Managed Build stage, followed by the Deliver Artifacts stage.
After the Build Pipeline execution is complete, we can view the file stored in the OCI Artifact Registry, which can then be downloaded to local workspace (Under Ellipses , choose Download
).