Skip to content

Commit 3e9d5df

Browse files
authored
Merge pull request #37 from oracle-devrel/pe
pe
2 parents 9437ac3 + 271206d commit 3e9d5df

27 files changed

+237
-3
lines changed

AIO.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
All in One reference for samples - In Alphabetical (A to Z) order.
22
-------
33

4+
- Access resource with Private IP from OCI Build runner - https://github.com/oracle-devrel/oci-devops-examples/tree/main/oci-build-examples/oci-devops-pa-with-private-oke
45
- Build Caching - https://github.com/oracle-devrel/oci-devops-examples/tree/main/oci-build-examples/oci-build-caching
56
- Build Native image with Graal VM Enterprise edition - https://github.com/oracle-devrel/oci-devops-examples/tree/main/oci-build-examples/oci_devops_build_with_graalenterprise
67
- Build a micronaut restapi application with Graal VM Enterprise - https://github.com/oracle-devrel/oci-devops-examples/tree/main/oci-build-examples/oci_devops_graalee_micronaut
@@ -26,3 +27,4 @@ All in One reference for samples - In Alphabetical (A to Z) order.
2627
- Invoke deployment pipeline on a container image upload - https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-deployment-examples/oci-devops-deploy-on-imageupload
2728
- OCI Policy management using terraform - https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-config-examples/oci_devops_policy_dg_terraform
2829
- Scanning code for vulnerabilities for Maven packages - https://github.com/oracle-devrel/oci-devops-examples/tree/main/oci-build-examples/oci-devops-vulnerability-audit-management
30+

oci-build-examples/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ All about OCI devops build samples ..
2020
* [Build a native executable application with Graal VM Enterprise](./oci_devops_build_with_graalenterprise/)
2121
* [Build a micronaut restapi application with Graal VM Enterprise](./oci_devops_graalee_micronaut/)
2222

23+
</details>
24+
25+
<details>
26+
<summary>Private resource access - click to expand</summary>
27+
28+
* [Access OKE with Private endpoint from build runner](./oci-devops-pa-with-private-oke/)
29+
30+
31+
2332
</details>
2433

2534

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Access resource with Private IP from OCI Build runner
2+
3+
This sample shows how to access resources which are with private IP addresses from an OCI Build runner.
4+
5+
## Accessing Private Virtual Network from Build runner
6+
7+
- You can access self-hosted repositories (GitLab Server and Bitbucket Server) with private IP from the Managed Build stage. With the private access configuration, you can write commands in the build specification file to access the private endpoints in your Virtual Cloud Network (VCN). During the build, the service-managed build runner facilitates the connection from the build stage to your tenancy subnet. Using FastConnect or other IPSec VPN peering solutions, you can also create a connection to access your on-premises code repository from an OCI DevOps build runner.
8+
9+
## Specific instruction to clone only this example.
10+
11+
```
12+
$ git init oci-devops-pa-with-private-oke
13+
$ cd oci-devops-pa-with-private-oke
14+
$ git remote add origin <url to this git repo>
15+
$ git config core. sparsecheckout true
16+
$ echo "oci-build-examples/oci-devops-pa-with-private-oke/*">>.git/info/sparse-checkout
17+
$ git pull --depth=1 origin main
18+
19+
```
20+
21+
## Objectives
22+
23+
- Create an [Container Engine for Kubernetes (OKE)](https://docs.oracle.com/en-us/iaas/Content/ContEng/home.htm)
24+
- Associate OCI DevOps Build runner via Private Access endpoints.
25+
- Test and validate the access
26+
27+
28+
## Procedure to use this illustration.
29+
30+
###OCI Notifications
31+
- Create an OCI notification topic - https://docs.oracle.com/en-us/iaas/Content/Notification/Tasks/managingtopicsandsubscriptions.htm#createTopic
32+
33+
### OCI Container Engine for Kubernetes (OKE)
34+
- Create Container Engine for Kubernetes (OKE) Cluster using Quick workflow - https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengcreatingclusterusingoke_topic-Using_the_Console_to_create_a_Quick_Cluster_with_Default_Settings.htm#create-quick-cluster
35+
36+
![](images/oci-oke-wizzard.png)
37+
38+
- Select `Private endpoints` and `Private workers`.
39+
40+
![](images/oci-oke-private-cluster-details.png)
41+
42+
43+
- Make a note of OKE's Cluster Id.
44+
45+
![](images/oci-oke-cluster-id.png)
46+
47+
💡Specific note on the network setup
48+
- When you build OKE via wizard it will set up necessary VCN, subnet, gateways, route tables etc.
49+
- But if you are using custom workflow for OKE or connection for any other resources from build runner, ensure to set up NAT or Service gateway accordingly.
50+
- When using with a Private access endpoint, the Build runner instance is considered as a private instance in your VCN during the network setup. Using only an internet gateway does not allow egress to the internet from a private subnet. Therefore, the VCN must have a Network Address Translation (NAT) gateway or service gateway with routing rules to forward traffic configured in the routing table for the private access configuration to succeed in the Managed Build stage.
51+
52+
### Validate VCN
53+
54+
- As we have used the `Quick workflow`, it has created the VCN and necessary details.
55+
- From `OKE details` identify `VCN Name` and click on the link.
56+
57+
![](images/oci-oke-vcn.png)
58+
59+
- There will be 3 subnets, one for endpoint, one for the load balancer and another one for nodes.
60+
61+
![](images/oci-vcn-subnets.png)
62+
63+
- Check the `Route tables` and check the `Route Table` for private subnets. There will be a `NAT Gateway` for access to the internet and a `Service Gateway` to access the OCI services.
64+
65+
![](images/oci-vcn-routerules.png)
66+
67+
### OCI DevOps.
68+
69+
- Create a DevOps project - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_project.htm#create_a_project.
70+
Associate with the notification topic.
71+
72+
![](images/oci-devops-project.png)
73+
74+
- Ensure to enable the logs for the DevOps project.
75+
76+
![](images/oci-devops-logs.png)
77+
78+
- Create an OCI code repo - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_repo.htm#create_repo and push this content to the repo.
79+
80+
![](images/oci-coderepo-files.png)
81+
82+
- Create an OCI Build pipeline - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_buildpipeline.htm
83+
84+
![](images/oci-devops-buildpipeline.png)
85+
86+
- Add the below parameters to the build pipeline with proper values.
87+
88+
- KUBECTL_VERSION - Version of the kubectl to be used - https://kubernetes.io/releases/,Example:1.24.0
89+
- OCI_OKE_OCID - Cluster ID of the OKE, Example: ocid1.cluster.oc1.us-sanjose-1.xx
90+
- OCI_REGION - OCI Region, Example: us-sanjose-1
91+
92+
![](images/oci-build-paramters.png)
93+
94+
95+
- Use the `+` and add a `Managed Build` stage.
96+
97+
![](images/oci-buildpipeline-addstages.png)
98+
99+
![](images/oci-buildmanagedbuild-stage.png)
100+
101+
- Provide a `Stage name` and `Stage description(Optional)`.
102+
103+
![](images/oci-build-mb-1.png)
104+
105+
- Click on `Connect to your tenancy subnet`
106+
- Select the VCN same as that of our private OKE.
107+
- Select oke-node subnet.
108+
109+
![](images/oci-build-mb-2.png)
110+
111+
- Click `Select` under `Primary code repository` and select the code repo of type `OCI Code Repository` created.
112+
113+
![](images/oci-build-mb-3.png)
114+
115+
- Click `Add`
116+
117+
![](images/oci-build-mb-4.png)
118+
119+
- Here the `Focus` is on accessing private IP-based resources from the build pipeline, to do so we are using sample kubectl actions, but the same can be extended as a full pipeline with other stages and connected to the deployment pipeline as well.
120+
121+
### Let's test
122+
123+
- Within the build pipeline, click `Start manual run` and start the pipeline.
124+
125+
![](images/oci-build-manual-run.png)
126+
127+
- Wait for all the steps to complete.
128+
129+
- View the build execution logs and validate the access.
130+
131+
![](images/oci-build-logs.png)
132+
133+
References
134+
==========
135+
136+
- Oracle Cloud Infrastructure DevOps - https://docs.oracle.com/en-us/iaas/Content/devops/using/home.htm
137+
138+
139+
Contributors
140+
===========
141+
142+
- Author: [Rahul M R](https://github.com/RahulMR42).
143+
- Collaborators: NA
144+
- Last release: August 2022
145+
146+
### Back to examples.
147+
----
148+
149+
- 🍿 [Back to OCI DevOps Build sample](./../README.md)
150+
- 🏝️ [Back to OCI DevOps sample](./../../README.md)
151+
152+
153+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
version: 0.1
2+
component: build
3+
timeoutInSeconds: 6000
4+
runAs: root
5+
shell: bash
6+
env:
7+
# these are local variables to the build config
8+
variables:
9+
# the value of a vaultVariable is the secret-id (in OCI ID format) stored in the OCI Vault service
10+
# you can then access the value of that secret in your build_spec.yaml commands
11+
vaultVariables:
12+
# EXAMPLE_SECRET: "YOUR-SECRET-OCID"
13+
# exportedVariables are made available to use as parameters in sucessor Build Pipeline stages
14+
# For this Build to run, the Build Pipeline needs to have a BUILDRUN_HASH parameter set
15+
exportedVariables:
16+
#Variable to export and use with in further stages.
17+
18+
inputArtifacts:
19+
- name: kubectl_cli
20+
type: URL
21+
url: https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl
22+
location: ${OCI_PRIMARY_SOURCE_DIR}/kubectl
23+
24+
25+
steps:
26+
- type: Command
27+
timeoutInSeconds: 6000
28+
name: "Access a Private OKE from Build runner"
29+
command: |
30+
cd ${OCI_PRIMARY_SOURCE_DIR}
31+
oci ce cluster create-kubeconfig --cluster-id ${OCI_OKE_OCID} --file kube_config --region ${OCI_REGION} --token-version 2.0.0 --kube-endpoint PRIVATE_ENDPOINT
32+
export KUBECONFIG=./kube_config
33+
chmod +x kubectl
34+
export PATH=${PATH}:${OCI_PRIMARY_SOURCE_DIR}
35+
kubectl get nodes
36+
echo "Applying SVC Config..."
37+
kubectl apply -f sample_oke_svc.yaml
38+
echo "Validate the SVC..."
39+
kubectl describe svc sample-svc
40+
echo "Delete the SVC..."
41+
kubectl delete -f sample_oke_svc.yaml
42+
onFailure:
43+
- type: Command
44+
command: |
45+
echo "Handling Failure"
46+
echo "Failure successfully handled"
47+
timeoutInSeconds: 40
48+
runAs: root
49+
50+
51+
#outputArtifacts:
52+
# - name: sample
53+
# type: DOCKER_IMAGE/BINARY
54+
# # this location tag doesn't effect the tag used to deliver the container image
55+
# # to the Container Registry
56+
# location:
125 KB
Loading
131 KB
Loading
115 KB
Loading
144 KB
Loading
170 KB
Loading

0 commit comments

Comments
 (0)