Skip to content

Commit 600b810

Browse files
author
odx-pipelines/[email protected]
committed
Connect to windows host from BP
1 parent e675f4a commit 600b810

23 files changed

+253
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
**.idea**
55
.AppleDouble
66
.LSOverride
7-
7+
Tests/*
8+
Tests
89
# Icon must end with two \r
910
Icon
1011

AIO.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
All in One reference for samples - In Alphabetical (A to Z) order.
22
-----
3+
4+
- A way (workaround) to execute commands on to a Windows machine using OCI Run command agent from OCI Build pipeline. - https://github.com/oracle-devrel/oci-devops-examples/tree/main/oci-build-examples/oci-devops-connect-to-windows-from-buildmachines
35
- 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
46
- Build Caching - https://github.com/oracle-devrel/oci-devops-examples/tree/main/oci-build-examples/oci-build-caching
57
- 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

oci-build-examples/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ All about OCI devops build samples ..
1212

1313
* [All about predefined system variables](./oci_build_parameters/)
1414

15+
</details>
16+
<details>
17+
<summary>Compute Agents executions</summary>
18+
19+
* [Run commands on WINDOWS host from build pipeline](./oci-devops-connect-to-windows-from-buildmachines/)
20+
21+
1522
</details>
1623

1724
<details>
@@ -44,6 +51,8 @@ All about OCI devops build samples ..
4451

4552

4653

54+
55+
4756
### Back to examples.
4857
----
4958

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
A way (workaround) to execute commands on to a Windows machine using OCI Run command agent from OCI Build Pipeline
2+
------
3+
4+
5+
6+
Objective
7+
---
8+
- Create an OCI DevOps build pipeline.
9+
- Create a windows host and enable compute run agent.
10+
- Execute commands on Windows hosts and fetch the result.
11+
12+
```
13+
$ git init oci-devops-connect-to-windows-from-buildmachines
14+
$ cd oci-devops-connect-to-windows-from-buildmachines
15+
$ git remote add origin <url to this git repo>
16+
$ git config core.sparsecheckout true
17+
$ echo "oci-build-examples/oci-devops-connect-to-windows-from-buildmachines/*">>.git/info/sparse-checkout
18+
$ git pull --depth=1 origin main
19+
20+
```
21+
22+
Audience: OCI Advanced users.
23+
24+
Procedure to use the illustration
25+
-------
26+
27+
### Compute instance.
28+
29+
- Create an OCI Compute instance with Windows operating system.
30+
31+
![](images/oci-compute-instance-1.png)
32+
33+
![](images/oci-compute-instance-2.png)
34+
35+
- Provide `VCN`, and `Subnet` information. A public IP address is optional, as we will be using the `OCI Run command agent` it does not need a public IP address for the connection.
36+
37+
- Ensure that the `Compute Instance Run command` agent is enabled.
38+
39+
![](images/oci-compute-agent.png)
40+
41+
### OCI identity setup.
42+
43+
- Create a dynamic group for computing instance/s with the below rule.
44+
```java
45+
All {instance.compartment.id = 'OCID OF WINDOWS HOST'}
46+
```
47+
- Create a dynamic group for the DevOps build pipeline with the below rule.
48+
49+
```java
50+
ALL {resource.type = 'devopsbuildpipeline', resource.compartment.id = 'OCID OF OCI COMPARTMENT'}
51+
```
52+
53+
- Create the below identity policies.
54+
```java
55+
Allow dynamic-group <NAME OF THE DG FOR BUILD PIPELINE> to manage objects in compartment <NAME OF THE COMPARTMENT>
56+
57+
Allow dynamic-group <NAME OF THE DG FOR BUILD PIPELINE> to manage ons-topics in compartment <NAME OF THE COMPARTMENT>
58+
59+
Allow dynamic-group <NAME OF THE DG FOR BUILD PIPELINE> ons-topics in compartment <NAME OF THE COMPARTMENT>
60+
61+
Allow dynamic-group <NAME OF THE DG FOR COMPUTE INSTANCES> to use instance-agent-command-execution-family in compartment <NAME OF THE COMPARTMENT>
62+
63+
Allow dynamic group <NAME OF THE DG FOR COMPUTE INSTANCES> to manage objects in compartment <NAME OF THE COMPARTMENT>
64+
65+
Allow dynamic-group <NAME OF THE DG FOR COMPUTE INSTANCES> to use instance-agent-command-execution-family in compartment <NAME OF THE COMPARTMENT>
66+
67+
```
68+
69+
### Object Storage.
70+
71+
- Create an `object storage bucket.
72+
73+
![](images/oci-object-bucket.png)
74+
75+
76+
### OCI DevOps.
77+
- Create an OCI notification topic - https://docs.oracle.com/en-us/iaas/Content/Notification/Tasks/managingtopicsandsubscriptions.htm#createTopic
78+
79+
- Create a DevOps project - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_project.htm#create_a_project
80+
81+
![](images/oci-devops-project.png)
82+
83+
- Enable logging for the DevOps project.
84+
85+
![](images/oci-devops-logs.png)
86+
87+
Click on Code Repository within the DevOps project resource and click on `Create repository. - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_repo.htm
88+
89+
![](images/oci-code-repo.png)
90+
91+
- Using the `ssh` or `https` method and push the whole content to the OCI Code repo - refer to details here - https://docs.oracle.com/en-us/iaas/Content/devops/using/clone_repo.htm
92+
93+
- Click on Build pipelines within DevOps project resources and click on Create build pipeline- https://docs.oracle.com/en-us/iaas/Content/devops/using/managing_build_pipelines.htm
94+
95+
![](images/oci-buildpipeline.png)
96+
97+
- Use `+` and add a stage.
98+
99+
![](images/oci-add-stage.png)
100+
101+
- Add a `Managed Build stage`.
102+
103+
![](images/oci-managed-build-stage.png)
104+
105+
- Provide the details and connect to the `OCI Code repo` as the primary source name.
106+
107+
![](images/oci-devops-add-source.png)
108+
109+
- Click `Add`.
110+
111+
- Add below `Build parameters` and actual values.
112+
113+
```java
114+
- OBJECTSTORAGE_NAMESPACE: OBJECT STORAGE NAMESPACE
115+
- OBJECTSTORAGE_BUCKET: OBJECT BUCKET NAME
116+
- INSTANCE_OCID : COMPUTE INSTANCE(WINDOWS) OCID
117+
- OCI_REGION : OCI Region identifier
118+
```
119+
120+
![](images/oci-build-params.png)
121+
122+
123+
### Validate the execution.
124+
125+
- Within the `Build pipeline` click `Start manual run`
126+
127+
![](images/oci-build-start.png)
128+
129+
- Wait for all the steps to finish.
130+
131+
- Validate the execution via build logs.
132+
- Verify the input and output file via object storage.
133+
![](images/oci-bucket-objects.png)
134+
- Verify the run command execution status via the instance `run command` option.
135+
![](images/oci-run-commands.png)
136+
- For any error during the execution you may do a trial run of `run command` against the compute instance from OCI Compute console view, validate the policies and groups and verify the build parameter
137+
- The `TIMEOUT_IN_SECONDS` value within build_spec.yaml file for the compute run command agent invoke is based on samples here, please update accordingly
138+
139+
140+
Read more
141+
---
142+
143+
- OCI DevOps service - https://docs.oracle.com/en-us/iaas/Content/devops/using/home.htm
144+
- OCI Compute run command agent - https://docs.oracle.com/en-us/iaas/Content/Compute/Tasks/runningcommands.htm
145+
146+
Contributors
147+
===========
148+
149+
- Author: [Rahul M R](https://github.com/RahulMR42).
150+
- Collaborators:
151+
- Last release: December 2022
152+
153+
### Back to examples.
154+
----
155+
156+
- 🍿 [Back to OCI Devops Build sample](./../README.md)
157+
- 🏝️ [Back to OCI Devops sample](./../../README.md)
158+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
LOCAL_CHECK_STATE: "SUCCEEDED" #Its a dummy variable for now ,but can be used if you wish to add more status checks across.
10+
TIMEOUT_IN_SECONDS: 700 #Its a timeout for compute agent execution.
11+
12+
steps:
13+
- type: Command
14+
name: " Update Object Storage"
15+
timeoutInSeconds: 200
16+
command: |
17+
cd ${OCI_PRIMARY_SOURCE_DIR}
18+
oci os object put --namespace ${OBJECTSTORAGE_NAMESPACE} --bucket-name ${OBJECTSTORAGE_BUCKET} --file input_windows.txt --no-multipart --force
19+
20+
# In the above step Using input_windows.txt file to push to object,if you wish to use different name ,please do update the content.json as well.
21+
22+
- type: Command
23+
name: "OCI Instance Agent Inovkation"
24+
timeoutInSeconds: 20000
25+
command: |
26+
cd ${OCI_PRIMARY_SOURCE_DIR}
27+
export BUILDRUN_HASH=`echo ${OCI_BUILD_RUN_ID} | rev | cut -c 1-7`
28+
if [ ! -e "instance.json" ] ; then
29+
echo '{"instanceId": "'${INSTANCE_OCID}'"}' > instance.json
30+
31+
fi
32+
cat content.json |envsubst >content_target.json
33+
cat content_target.json
34+
COMPARTMENT_OCID=$(oci devops build-pipeline get --build-pipeline-id $OCI_PIPELINE_ID --query "data.\"compartment-id\"" --raw-output)
35+
oci instance-agent command create --compartment-id ${COMPARTMENT_OCID} --content file://content_target.json --target file://instance.json --timeout-in-seconds ${TIMEOUT_IN_SECONDS} --display-name "cmd_by_build_${BUILDRUN_HASH}"
36+
echo "Invoked Command exec with a display - cmd_by_build_${BUILDRUN_HASH}"
37+
echo "Sleeping for ${TIMEOUT_IN_SECONDS} seconds...."
38+
sleep ${TIMEOUT_IN_SECONDS}
39+
40+
41+
- type: Command
42+
name: "Read from Object storage"
43+
timeoutInSeconds: 10000
44+
command: |
45+
cd ${OCI_WORKSPACE_DIR}/${code_repo_name}
46+
if [ "${LOCAL_CHECK_STATE}" != "FAILED" ] ;then
47+
oci os object get --namespace ${OBJECTSTORAGE_NAMESPACE} --bucket-name ${OBJECTSTORAGE_BUCKET} --file from_object_store.txt --name output_windows.txt
48+
echo """"""""""""""""""""""""""""""""Execution Output""""""""""""""""""""""""""""""""""""""""""""""""""
49+
cat from_object_store.txt
50+
echo """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
51+
fi
52+
53+
# In the above steps ,reading the agent execution output from a file named output_windows.txt,for any changes ,do update the content.json as well.
54+
55+
56+
57+
58+
59+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"output":
3+
{
4+
"bucketName": "${OBJECTSTORAGE_BUCKET}",
5+
"namespaceName": "${OBJECTSTORAGE_NAMESPACE}",
6+
"objectName": "output_windows.txt",
7+
"outputType": "OBJECT_STORAGE_TUPLE",
8+
"outputUri": "https://objectstorage.${OCI_REGION}.oraclecloud.com/n/${OBJECTSTORAGE_NAMESPACE}/b/${OBJECTSTORAGE_BUCKET}/o/output_windows.txt"
9+
},
10+
11+
"source":
12+
{
13+
"bucketName": "${OBJECTSTORAGE_BUCKET}",
14+
"namespaceName": "${OBJECTSTORAGE_NAMESPACE}",
15+
"objectName": "input_windows.txt",
16+
"sourceType": "OBJECT_STORAGE_TUPLE",
17+
"sourceUri": "https://objectstorage.${OCI_REGION}.oraclecloud.com/n/${OBJECTSTORAGE_NAMESPACE}/b/${OBJECTSTORAGE_BUCKET}/o/input_windows.txt"
18+
}
19+
20+
}
37.7 KB
Loading
146 KB
Loading
160 KB
Loading
86.1 KB
Loading

0 commit comments

Comments
 (0)