Skip to content

Commit 9a984e0

Browse files
authored
Merge pull request #57 from oracle-devrel/ci
ci sample via shell stage
2 parents 0c9cfb9 + 3113012 commit 9a984e0

Some content is hidden

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

46 files changed

+645
-1
lines changed

AIO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- Sample illustration of OCI DevOps deployment pipeline with *STAGE LEVEL PARAMETERS* - https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-deployment-examples/oci-deployment-stagelevelparams
3131
- Sample illustration of OCI DevOps deployment pipeline with DevOps Deploy Shell stage - https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-deployment-examples/oci-deployment-shell-stages
3232
- Sample illustration of OCI Devops deployment pipeline to update the deployment environment - Instances dynamically - https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-deployment-examples/oci-devops-instance-env-dynamic-update
33+
- Sample illustration of deployment on to *OCI Container instance* using OCI DevOps. https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-deployment-examples/oci-devops-deploy-containerinstance
3334
- Sample illustration of verifying the *integrity of Helm chart* before the deployment https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-deployment-examples/oci-deployment-with-helm-attestation
3435
- 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
3536
- Trigger build-pipeline from OCI Code repo on file modifications . - https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-coderepo-examples/oci-devops-coderepo-filebasedtrigger

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ The service also provides private Git repositories to store your code and it sup
1818
- [⚡ OCI Devops Projects,Policies and Groups - sample](./oci-config-examples/README.md)
1919

2020
### Recent samples.
21+
- 🛎[Sample illustration of deployment on to *OCI Container instance* using OCI DevOps.]( https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-deployment-examples/oci-devops-deploy-containerinstance
22+
)
2123
- 🛎️[Sample illustration of verifying the *integrity of Helm chart* before the deployment](https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-deployment-examples/oci-deployment-with-helm-attestation)
2224
- 🛎️[Sample illustration of OCI DevOps deployment pipeline with DevOps Deploy Shell stage.]( https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-deployment-examples/oci-deployment-shell-stages)
2325
- 🛎️[A sample to run OCI AI Anomaly detection from OCI Build-pipeline.](https://github.com/oracle-devrel/oci-devops-examples/tree/main/oci-build-examples/oci-devops-anomaly-detection)
24-
- 🛎[Sample illustration of OCI DevOps deployment pipeline with stage level paramters.]( https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-deployment-examples/oci-deployment-stagelevelparams)
26+
2527

2628
## All samples (A to Z sorted order)
2729

oci-deployment-examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ All about OCI devops deployment samples ..
4545
<details>
4646
<summary>Shell stages - click to expand</summary>
4747

48+
* [Deploy to Container instances using shell stage](./oci-devops-deploy-containerinstance)
4849
* [Using shell stages with deployment pipeline](./oci-deployment-shell-stages/)
4950

5051
</details>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# General
2+
**/.DS_Store
3+
.AppleDouble
4+
.LSOverride
5+
.idea
6+
tmp
7+
8+
oci-devops-instances-with-graal/*
9+
oci-devops-instances-with-graal
10+
oci-devops-graal-micronaut-deploy-to-instances/*
11+
oci-devops-graal-micronaut-deploy-to-instances
12+
13+
# Local .terraform directories
14+
**/.terraform/*
15+
16+
# .tfstate files
17+
*.tfstate
18+
*.tfstate.*
19+
*.zip*
20+
*.tfvars
21+
*.out
22+
plan.json
23+
24+
# terraform lock file
25+
**/.terraform.lock.hcl
26+
27+
# Icon must end with two \r
28+
Icon
29+
30+
31+
# Thumbnails
32+
._*
33+
34+
# Files that might appear in the root of a volume
35+
.DocumentRevisions-V100
36+
.fseventsd
37+
.Spotlight-V100
38+
.TemporaryItems
39+
.Trashes
40+
.VolumeIcon.icns
41+
.com.apple.timemachine.donotpresent
42+
43+
# Directories potentially created on remote AFP share
44+
.AppleDB
45+
.AppleDesktop
46+
Network Trash Folder
47+
Temporary Items
48+
.apdisk
49+
50+
# ignore common security keys
51+
*.key
52+
*.crt
53+
*.csr
54+
*.pem
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
2+
Sample illustration of deployment on to *OCI Container instance* using OCI DevOps.
3+
------------
4+
5+
Objective
6+
----
7+
8+
- Using OCI Build pipeline build a container image for a sample python application.
9+
- Use the shell stage within the deployment pipeline to deploy to the container instance.
10+
11+
Specific instructions to download only this sample.
12+
---
13+
14+
```
15+
$ git init oci-devops-deploy-containerinstance
16+
$ cd oci-devops-deploy-containerinstance
17+
$ git remote add origin https://github.com/oracle-devrel/oci-devops-examples
18+
$ git config core. sparsecheckout true
19+
$ echo "oci-deployment-examples/oci-devops-deploy-containerinstance/*">>.git/info/sparse-checkout
20+
$ git pull --depth=1 origin main
21+
22+
```
23+
24+
Procedure
25+
---
26+
27+
### OCI Identity setup.
28+
29+
- Create OCI Dynamic group and add the below rules.
30+
31+
```java
32+
ALL {resource.type = 'devopsbuildpipeline', resource.compartment.id = 'OCID OF YOUR COMPARTMENT'}
33+
ALL {resource.type = 'devopsdeploypipeline', resource.compartment.id = 'OCID OF YOUR COMPARTMENT'}
34+
```
35+
36+
- Create OCI policy and add the below statements.
37+
38+
```java
39+
Allow dynamic-group <NAME OF THE DYNAMIC GROUP> to read secret-family in compartment <NAME OF THE COMPARTMENT>
40+
Allow dynamic-group <NAME OF THE DYNAMIC GROUP> to manage virtual-network-family in compartment <NAME OF THE COMPARTMENT>
41+
Allow dynamic-group <NAME OF THE DYNAMIC GROUP> to manage ons-topics in compartment <NAME OF THE COMPARTMENT>
42+
Allow dynamic-group <NAME OF THE DYNAMIC GROUP> to manage objects in compartment <NAME OF THE COMPARTMENT>
43+
Allow dynamic-group <NAME OF THE DYNAMIC GROUP> to manage all-artifacts in compartment <NAME OF THE COMPARTMENT>
44+
Allow dynamic-group <NAME OF THE DYNAMIC GROUP> to manage repos in compartment <NAME OF THE COMPARTMENT>
45+
Allow dynamic-group <NAME OF THE DYNAMIC GROUP> to manage compute-container-family in compartment <NAME OF THE COMPARTMENT>
46+
```
47+
48+
### OCI Artifact repo setup
49+
50+
- Create an OCI Artifact registry repo - https://docs.oracle.com/en-us/iaas/Content/artifacts/create-repo.htm#create-repo
51+
- Uncheck the immutable option, this is to have a mutable command spec configuration.
52+
53+
![](images/oci-artifact-repo.png)
54+
55+
### OCI Container registry setup
56+
57+
- Create an OCI container registry repo - https://docs.oracle.com/en-us/iaas/Content/Registry/Tasks/registrycreatingarepository.htm#Creating_a_Repository
58+
59+
![](images/oci-container-repo.png)
60+
61+
### OCI VCN Setup
62+
63+
- Create a VCN - https://docs.oracle.com/en-us/iaas/Content/Network/Tasks/managingVCNs.htm
64+
- We have created this sample using a `public subnet`, feel free to use a private or public subnet as far as the IP address can connect via HTTP from your workstation.
65+
- With in the subnet ,add security rules to allow traffic http (port 80) and https (port 443).
66+
67+
![](images/oci-vcn-secrules.png)
68+
69+
### OCI Vault setup
70+
71+
- Create an OCI Vault and master key - https://docs.oracle.com/en-us/iaas/Content/KeyManagement/home.htm
72+
- We will be using an object storage backend to ensure a consistent state across the container instance, to ensure the same IP address for a better user experience. To provide access create a `customer secret key` - https://docs.oracle.com/en-us/iaas/Content/Identity/Tasks/managingcredentials.htm#Working2
73+
74+
![](images/oci-aws-secretkey.png)
75+
76+
- Add the key id and key as secrets with OCI Vault.
77+
78+
![](images/oci-access-keys.png)
79+
80+
- Make a note of these secrets OCID
81+
82+
### OCI Object storage bucket.
83+
84+
- Create an OCI Object storage bucket, the same will be used to store terraform config and state files.
85+
86+
![](images/oci-os-bucket.png)
87+
88+
89+
90+
### OCI DevOps setup
91+
92+
- Create an `OCI Notification topic` - https://docs.oracle.com/en-us/iaas/Content/Notification/Tasks/create-topic.htm#top
93+
- Create a DevOps project and associate it with the notification.
94+
95+
![](images/oci-devops-project.png)
96+
97+
- Enable `logs` for the project.
98+
99+
- Create a code repo. - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_repo.htm#create_repo
100+
101+
![](images/oci-code-repo.png)
102+
103+
- Push the content to the code repo over HTTPS or ssh protocol.
104+
105+
- Create a DevOps artifact of type `Docker image`, this is for static image reference. Use type as `Container Image repository` and path as `PATH To container repo:${STATIC_IMAGE_TAG}`.Enable `Allow parameterization`.
106+
107+
![](images/oci-static-image-artifact.png)
108+
109+
- Create a DevOps artifact of type `Docker image`, this for dynamic image reference. Use type as `Container Image repository` and path as `PATH To container repo:${BUILDRUN_HAS}`.Enable `Allow parameterization`.
110+
111+
![](images/oci-dynamic-image-tag.png)
112+
113+
- Create a DevOps artifact of type `General artifact` for the build pipeline to push shell stage instructions to the artifact registry repo. Select the type as `General artifact` and the artifact source as `Artifact registry repository`
114+
115+
![](images/oci-artifact-generic.png)
116+
117+
- Use `Select` and associate with the artifact registry repo.
118+
119+
![](images/oci-artifact-generic-2.png)
120+
121+
- Use artifact location as `Set custom location` and add the path as `commad_spec.yaml` and version as `0.0`.Enable the `Allow parameterization` option.
122+
123+
![](images/oci-ga-yaml-3.png)
124+
125+
126+
- Create a DevOps artifact of type `Command specification` for the shell stage to use the artifact. We will be using the definitions created in the previous step but with a different artifact type. Select the type as `Command specification` and the artifact source as `Artifact registry repository`
127+
128+
![](images/oci-artifact-shellstage-1.png)
129+
130+
- Use `Select` and associate with the artifact registry repo.
131+
132+
![](images/oci-artifact-shellstage-2.png)
133+
134+
135+
- Use artifact location as `Set custom location` and add the path as `commad_spec.yaml` and version as `0.0`.Enable the `Allow parameterization` option.
136+
137+
![](images/oci-ga-yaml-3.png)
138+
139+
- Create a `Build pipeline` - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_buildpipeline.htm#create_buildpipeline
140+
141+
![](images/oci-build-pipeline.png)
142+
143+
- Add below keys and values for the build pipeline, as parameters.
144+
145+
![](images/oci-build-params.png)
146+
147+
148+
- BUCKET_NAME = Object storage bucket name
149+
- NAMESPACE_NAME = Object storage namespace
150+
- SUBNET_OCID = OCID of the subnet to use
151+
- IMAGE_STATIC_TAG = a string (Example new), it's a tag we will be using to update the container image.
152+
- CONTAINER_REGISTRY_URL = Absolute path of the container registry repo.
153+
- CONTAINERINSTANCE_DISPLAY_NAME = Display name for the container instance
154+
- AD = Availability domain for the container instance.
155+
- COMPARTMENT_OCID = OCI Compartment OCID
156+
- REGION = OCI Region
157+
158+
- Within the build pipeline add a stage of type `Managed Build`.Associate with the code repo as the `Primary code repository`.
159+
160+
![](images/oci-build-stage.png)
161+
162+
- Add another stage of type `Deliver Artifacts` within the build pipeline. Associate the stage with both the docker image and general artifacts created. Associate both the docker image artifact with the result artifact name as `python_app_dockerimage` and the general artifact with the outputArtifact name `command_spec`. This configuration is based on the [build_spec.yaml](build_spec.yaml) file.
163+
164+
```java
165+
outputArtifacts:
166+
- name: python_app_dockerimage
167+
type: DOCKER_IMAGE
168+
location: python_fast_app:latest
169+
170+
- name: command_spec
171+
type: BINARY
172+
location: ${OCI_PRIMARY_SOURCE_DIR}/command_spec.yaml
173+
```
174+
![](images/oci-uploadartifact-stage.png)
175+
176+
- Create a deployment pipeline - https://docs.oracle.com/en-us/iaas/Content/devops/using/deployment_pipelines.htm
177+
178+
![](images/oci-deployment-pipeline.png)
179+
180+
- Within the deployment pipeline add a stage of type `shell.` Associate with the command specification artifacts.
181+
182+
![](images/oci-shell-stage-1.png)
183+
184+
- Select the appropriate container instance configuration.
185+
186+
![](images/oci-shell-stage-2.png)
187+
188+
- Select the appropriate virtual cloud network and subnet.
189+
190+
![](images/oci-shell-stage-3.png)
191+
192+
- Switch back to `build a pipeline` and add a stage of type `Trigger deployment`. Associate with the `deployment pipeline`.Ensure to enable the option `Send build pipelines Parameters`.
193+
194+
![](images/oci-invoke-deploy.png)
195+
196+
- the complete build pipeline stage will be as below.
197+
198+
![](images/oci-build-stages.png)
199+
200+
- Create an OCI Trigger and associate the code repo and the build pipeline created - https://docs.oracle.com/en-us/iaas/Content/devops/using/trigger_build.htm
201+
202+
![](images/oci-devops-trigger.png)
203+
204+
### Test the solution
205+
206+
- Update file [readme.md](README.md) and push back to code repo. Once the repo gets updated, it will trigger a build pipeline.
207+
208+
![](images/oci-build-trigger.png)
209+
210+
- Wait for all the build stages to complete.
211+
212+
![](images/oci-all-stages.png)
213+
214+
- Follow deployments
215+
216+
![](images/oci-deployments-progress.png)
217+
- It will take a while for the deployment pipeline to complete. Once done fetch the `IP address` to access the application from the deployment logs.
218+
219+
![](images/oci-ci-ip.png)
220+
221+
- We are restarting the container instance on every deployment to
222+
- Ensure a constant URL for the end user.
223+
- As there is no native image update for the container, on every restart it will pick the latest image pushed to the container repo.
224+
- Use the application IP and access the container.
225+
226+
![](images/oci-ci-container-ip.png)
227+
228+
### Tail end
229+
230+
- Refer deployment logs via pipeline or container instances will help to troubleshoot any errors.
231+
- The shell stage intern uses container instances with two containers and it will be auto-deleted once the deployment completes.
232+
233+
![](images/oci-ci-instances.png)
234+
235+
- The terraform state is managed by the object storage, once it's removed or any alteration, the terraform actions will also be changed accordingly.
236+
237+
### Cleanup of the resources.
238+
239+
- Delete OCI devops project using `cascade deletion` option.
240+
- Remove the content and bucket of OCI Object storage.
241+
- Delete the OCI Container instance.
242+
- Remove the artifacts and delete artifact and container registry repos.
243+
- Clean up the devops logs /policies /dynamic group as accordingly.
244+
245+
246+
Read more
247+
----
248+
249+
- OCI DevOps - https://docs.oracle.com/en-us/iaas/Content/devops/using/home.htm.
250+
- OCI Reference architectures - https://docs.oracle.com/solutions/
251+
- OCI DevOps samples - https://github.com/oracle-devrel/oci-devops-examples
252+
- OCI DevOps shell stages - https://docs.oracle.com/en-us/iaas/Content/devops/using/shell_stage.htm
253+
Contributors
254+
===========
255+
256+
- Author: Rahul M R.
257+
- Collaborators : NA
258+
- Last release: March 2023
259+
260+
### Back to examples.
261+
----
262+
- 🍿 [Back to OCI Devops Deployment sample](./../README.md)
263+
- 🏝️ [Back to OCI Devops sample](./../../README.md)**
264+

0 commit comments

Comments
 (0)