Skip to content

Commit f2a4a51

Browse files
author
fahdabidiroottenancy/Rahul
committed
Golan and Rust sample
1 parent 5f1a59c commit f2a4a51

File tree

77 files changed

+852
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+852
-0
lines changed

oci-pipeline-examples/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ All about devops pipelines using OCI Devops.
1515

1616
</details>
1717

18+
</details>
19+
<details>
20+
<summary>RUST Applications - click to expand</summary>
21+
22+
* [Build and Deploy a RUST application using OCI Devops](./oci-devops-cicd-rust-sample/)
23+
24+
</details>
25+
26+
27+
</details>
28+
<details>
29+
<summary>Golan Applications - click to expand</summary>
30+
31+
* [Build and Deploy a Golan application using OCI Devops](./oci-devops-golan-sample/)
32+
33+
</details>
34+
35+
1836

1937
### Back to examples.
2038
----
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/target
2+
**/*.rs.bk
3+
.vscode
4+
.DS_Store
5+
.gitignore
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
/target/
4+
5+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
6+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
7+
Cargo.lock
8+
9+
# These are backup files generated by rustfmt
10+
**/*.rs.bk
11+
12+
.DS_Store
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "helloworldapp"
3+
version = "0.0.0"
4+
authors = ["Rahul MR"]
5+
6+
[dependencies]
7+
rocket = "0.4.5"
8+
serde = { version = "1.0", features = ["derive"] }
9+
10+
[dependencies.rocket_contrib]
11+
version = "0.4.5"
12+
features = ["handlebars_templates"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM rust
2+
3+
ENV ROCKET_ADDRESS=0.0.0.0
4+
ENV ROCKET_PORT=8080
5+
6+
WORKDIR /app
7+
COPY . .
8+
9+
RUN rustup default nightly
10+
RUN cargo build
11+
12+
CMD ["cargo", "run"]
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
Sample illustration of [RUST](https://www.rust-lang.org/) application with [ROCKET](https://rocket.rs/) web framework.
2+
3+
------------
4+
5+
Objective
6+
---
7+
8+
- Create OCI Devops build pipeline.
9+
- Build a Rust Rocket simple sample application.
10+
- Push the artifact to OCI Container repo.
11+
- Use OCI Deployment pipeline and deploy to OCI OKE.
12+
13+
14+
Procedure
15+
---
16+
17+
- Create an OCI container registry . https://docs.oracle.com/en-us/iaas/Content/Registry/home.htm
18+
19+
![](images/oci-container-repo.png)
20+
21+
- Create an OCI artifact registry . https://docs.oracle.com/en-us/iaas/Content/artifacts/home.htm
22+
23+
![](images/oci-artifact-repo.png)
24+
25+
- Set policies & create a devops project - https://docs.oracle.com/en-us/iaas/Content/devops/using/home.htm.
26+
27+
![](images/oci-devops-project.png)
28+
29+
- Create devops artifacts. - https://docs.oracle.com/en-us/iaas/Content/devops/using/artifacts.htm
30+
31+
- Create an artifact with type `Docker image` for build to push the artifact. Ensure use your `container repo` url.
32+
33+
![](images/oci-devops-artifact-docker.png)
34+
35+
36+
- Create an artifact as type `Kubernetes manifest`. Ensure to add your `artifact repo` path.
37+
38+
![](images/oci-artifact-repo-path.png)
39+
40+
![](images/oci-artifact-repo-path-2.png)
41+
42+
43+
- You can clone this repo and push to an OCI Code repo .Or create GitHub repo by `importing` this repo to your github profile.
44+
45+
- Managing code repo for OCI Devops - https://docs.oracle.com/en-us/iaas/Content/devops/using/managing_coderepo.htm
46+
47+
48+
- Create an OCI devops build pipeline. https://docs.oracle.com/en-us/iaas/Content/devops/using/create_buildpipeline.htm
49+
50+
![](images/oci-devops-buidpipeline.png)
51+
52+
- Add a `manage build` stage to the build pipe line . https://docs.oracle.com/en-us/iaas/Content/devops/using/add_buildstage.htm
53+
54+
![](images/oci-manage-build-1.png)
55+
56+
- Accordingly select the `code repo /connection type /repo name`.
57+
58+
![](images/oci-manage-build-2.png)
59+
60+
- Add an `Upload artifact` stage to the build pipeline.
61+
62+
![](images/oci-build-upload-artifact-1.png)
63+
64+
- Select the two `artifacts` created.
65+
66+
![](images/oci-build-upload-artifact-2.png)
67+
68+
- Associate the build stage artifact names .
69+
70+
![](images/oci-build-upload-artifact-3.png)
71+
72+
- Snippet from [build_spec.yaml.](build_spec.yaml)
73+
74+
```
75+
outputArtifacts:
76+
- name: rust_app_base_image
77+
type: DOCKER_IMAGE
78+
# this location tag doesn't effect the tag used to deliver the container image
79+
# to the Container Registry
80+
location: rust_app_base:latest
81+
82+
- name: rust_kube_manifest
83+
type: BINARY
84+
# this location tag doesn't effect the tag used to deliver the container image
85+
# to the Container Registry
86+
location: ${OCI_PRIMARY_SOURCE_DIR}/deployment_manifest.yaml
87+
```
88+
89+
- Create a new OKE (With public endpoint and public or private workers) - https://docs.oracle.com/en-us/iaas/Content/ContEng/home.htm .You may reuse an existing one accordingly . Use `Access cluster` option to set your access to `OKE`.
90+
91+
![](images/oci-oke.png)
92+
93+
- Create a new devops environment as type `Kubernete Cluster`.-https://docs.oracle.com/en-us/iaas/Content/devops/using/create_oke_environment.htm
94+
95+
![](images/oci-devops-oke-env.png)
96+
97+
- Create a new devops deployment pipeline. - https://docs.oracle.com/en-us/iaas/Content/devops/using/deployment_pipelines.htm
98+
99+
![](images/oci-devops-deployment.png)
100+
101+
![](images/oci-deploy-oke-stage.png)
102+
103+
- Create a `deployment parameter` as `namespace` and give a namespace value.
104+
105+
![](images/oci-deploy-param.png)
106+
107+
- Add a new stage `invoke deployment` to the `build pipeline`. - https://docs.oracle.com/en-us/iaas/Content/devops/using/triggerdeploy_stage.htm
108+
109+
![](images/oci-deploy-trigger-deployment.png)
110+
111+
- Associate the deployment pipeline.
112+
113+
![](images/oci-deploy-invoke-build.png)
114+
115+
![](images/oci-devops-buildpipeline-all-stages.png)
116+
117+
Test the pipeline & Application
118+
-----
119+
120+
- Let test now . Use a `manual run` and invoke the build pipeline.
121+
122+
![](images/oci-devops-build-manual-run.png)
123+
124+
- Wait for all the stages to complete
125+
126+
![](images/oci-build-stage-status.png)
127+
128+
- After the `Trigger deployment` stage ,switch to `deployment pipeline` and follow the completion of stage.
129+
130+
![](images/oci-deployment-stage-status.png)
131+
132+
- Once it done switch to `cloud shell` or a `terminal` where you have access to the `OKE`.
133+
134+
- Use `OKE Access Cluster` option via console to set the `kubernetes context`.
135+
136+
![](images/oci-oke-access-cluster.png)
137+
138+
- Use `kubectl` commands and validate the application.
139+
140+
```
141+
kubectl get ns <namespace>
142+
```
143+
144+
![](images/kubectl-get-ns.png)
145+
146+
- Fetch the application loadbalancer EXTERNAL-IP to access the app.
147+
148+
```
149+
kubectl get all -n <namespace>
150+
151+
```
152+
153+
![](images/kubect-get-all.png)
154+
155+
- Launch the application via the browser or via curl.
156+
157+
```
158+
curl http://EXTERNAL-IP/v0/hello
159+
```
160+
161+
![](images/app-curl-view.png)
162+
163+
164+
![](images/app-browser-view.png)
165+
166+
- Incase of a wrong url you may get an exception as well like below.
167+
168+
```
169+
We lost with the path '/wrongpath'
170+
```
171+
172+
Read more
173+
----
174+
175+
- OCI Devops - https://docs.oracle.com/en-us/iaas/Content/devops/using/home.htm.
176+
- OCI Reference architectures - https://docs.oracle.com/solutions/
177+
- OCI Devops samples - https://github.com/oracle-devrel/oci-devops-examples
178+
179+
Contributors
180+
===========
181+
182+
- Author : Rahul M R.
183+
- Colloboroators : NA
184+
- Last release : May 2022
185+
186+
### Back to examples.
187+
----
188+
189+
- 🍿 [Back to OCI Devops Pipeline sample](./../README.md)
190+
- 🏝️ [Back to OCI Devops sample](./../../README.md)
191+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
10+
# the value of a vaultVariable is the secret-id (in OCI ID format) stored in the OCI Vault service
11+
# you can then access the value of that secret in your build_spec.yaml commands
12+
vaultVariables:
13+
14+
# exportedVariables are made available to use as parameters in sucessor Build Pipeline stages
15+
# For this Build to run, the Build Pipeline needs to have a BUILDRUN_HASH parameter set
16+
exportedVariables:
17+
- BUILDRUN_HASH
18+
19+
steps:
20+
- type: Command
21+
name: "Define unique image tag"
22+
timeoutInSeconds: 40
23+
command: |
24+
export BUILDRUN_HASH=`echo ${OCI_BUILD_RUN_ID} | rev | cut -c 1-7`
25+
echo "BUILDRUN_HASH: " $BUILDRUN_HASH
26+
27+
# Its an optional stage if you need the rust and cargo to be installed on build .In our case the whole action is managed by docker container.
28+
- type: Command
29+
timeoutInSeconds: 600
30+
name: "Build the app"
31+
command: |
32+
cd ${OCI_PRIMARY_SOURCE_DIR}
33+
curl https://sh.rustup.rs -sSf | sh -s -- -y
34+
35+
36+
onFailure:
37+
- type: Command
38+
command: |
39+
echo "Handling Failure"
40+
echo "Failure successfully handled"
41+
timeoutInSeconds: 40
42+
runAs: root
43+
44+
- type: Command
45+
timeoutInSeconds: 1200
46+
name: "Build container image"
47+
command: |
48+
cd ${OCI_PRIMARY_SOURCE_DIR}
49+
docker build --pull --rm -t rust_app_base .
50+
51+
outputArtifacts:
52+
- name: rust_app_base_image
53+
type: DOCKER_IMAGE
54+
# this location tag doesn't effect the tag used to deliver the container image
55+
# to the Container Registry
56+
location: rust_app_base:latest
57+
58+
- name: rust_kube_manifest
59+
type: BINARY
60+
# this location tag doesn't effect the tag used to deliver the container image
61+
# to the Container Registry
62+
location: ${OCI_PRIMARY_SOURCE_DIR}/deployment_manifest.yaml
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
kind: Namespace
2+
apiVersion: v1
3+
metadata:
4+
name: ${namespace}
5+
---
6+
apiVersion: apps/v1
7+
kind: Deployment
8+
metadata:
9+
name: sample-rust-app-deployment
10+
namespace: ${namespace}
11+
spec:
12+
selector:
13+
matchLabels:
14+
app: sample-rust-app
15+
replicas: 3
16+
template:
17+
metadata:
18+
labels:
19+
app: sample-rust-app
20+
spec:
21+
containers:
22+
- name: sample-rust-app
23+
# enter the path to your image, be sure to include the correct region prefix
24+
image: us-ashburn-1.ocir.io/xxxx/rahul/mr-devops/mr-devops-rust-sample:${BUILDRUN_HASH}
25+
imagePullPolicy: Always
26+
ports:
27+
- containerPort: 8080
28+
protocol: TCP
29+
livenessProbe:
30+
exec:
31+
command:
32+
- cat
33+
initialDelaySeconds: 5
34+
periodSeconds: 5
35+
---
36+
apiVersion: v1
37+
kind: Service
38+
metadata:
39+
name: sample-rust-app-service
40+
namespace: ${namespace}
41+
annotations:
42+
service.beta.kubernetes.io/oci-load-balancer-shape: "10Mbps"
43+
spec:
44+
type: LoadBalancer
45+
ports:
46+
- port: 80
47+
protocol: TCP
48+
targetPort: 8080
49+
selector:
50+
app: sample-rust-app
11.1 KB
Loading
6.32 KB
Loading

0 commit comments

Comments
 (0)