We will also be using the OCI Object Storage as a caching layer for our builds.
Prerequisites
Start by creating a runner in your repo's UI. This step is important to get the registration token needed to register the runner
Setting up the GitLab Runner
Under:
CI/CD Settings -> Runners -> create a new runner:
Save the token somewhere safe as we will need it later
Generate S3 Compatible Credentials for OCI Object Storage
To use OCI Object Storage as a caching layer, we need to create S3 compatible credentials.
Go to the OCI Console.
Navigate to Identity -> Domains.
Select your domain.
Go to the User management tab.
Select your user.
Create a key pair for S3 compatible access under the Customer secret keys tab:
Create a new Policy in OCI IAM
We'll use Terraform to create a new policy that allows access to Object Storage for our GitLab Runner. Here is an example policy you can use, replace <your-namespace> and <your-bucket-name> with your actual namespace and bucket name.
resource "oci_identity_policy" "object_storage_lifecycle_policy" {
name = "object-storage-lifecycle-policy"
description = "Allow Object Storage service to manage objects for lifecycle policies"
compartment_id = var.TENANCY_OCID
statements = [
"Allow group OCI_Administrators to manage buckets in tenancy",
"Allow group OCI_Administrators to manage objects in tenancy",
format("Allow service objectstorage-%s to manage object-family in tenancy", var.REGION)
]
}
Create OCI Object Storage Bucket
You can create the bucket using Terraform as well. We will use depends_on to ensure the policy is created before the bucket.
You can see the token generated earlier passed as a variable to the Terraform script under gitlab_runner_authentication_token and the key and secret for S3 compatible access as s3_key and s3_secret.