Skip to content

Commit 352c0c7

Browse files
committed
Add sample for OCI context with base image trigger
Signed-off-by: Sajay Antony <[email protected]>
1 parent 604da86 commit 352c0c7

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

windows-oci-context/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Using an OCI context
2+
3+
The sample below builds a windows image based on an OCI context.
4+
5+
> These are `powershell` commands.
6+
7+
## Bundle up the context into an OCI Artifact
8+
9+
The context has a simple `Dockerfile` and a `hello.txt`
10+
Use oras to create the context and ensure you are in `context` directory.
11+
12+
```shell
13+
$REGISTRY="myregistry"
14+
$REGISTRY_LOGIN_SERVER="myregistry.azurecr.io"
15+
cd context
16+
az acr login -n $REGISTRY
17+
oras push $REGISTRY_LOGIN_SERVER/windows/oci-context:latest .
18+
```
19+
20+
## Create an ACR to use the context
21+
22+
Create a base image trigger enabled task with the new context and ensure that you specify the required `--platform`.
23+
24+
```powershell
25+
$REGISTRY="myregistry"
26+
$REGISTRY_LOGIN_SERVER="myregistry.azurecr.io"
27+
az acr task create `
28+
--registry $REGISTRY `
29+
--name ocicontextbuild `
30+
--platform Windows/amd64 `
31+
--image "windowsimage:{{.Run.ID}}" `
32+
--context "oci://$REGISTRY_LOGIN_SERVER/windows/oci-context:latest" `
33+
--file Dockerfile `
34+
--commit-trigger-enabled false `
35+
--base-image-trigger-enabled true
36+
```
37+
38+
## Run the task to build and register the base image
39+
40+
Execute the task to build the container image.
41+
42+
```powershell
43+
$REGISTRY="myregistry"
44+
az acr task run --name ocicontextbuild --registry $REGISTRY
45+
```
46+
47+
The output should confirm that the base images were identified.
48+
49+
```
50+
...
51+
- image:
52+
registry: myregistry.azurecr.io
53+
repository: windowsimage
54+
tag: cf1bun
55+
digest: sha256:90f3c6534f9ed4ed8fa5bdaca006e284f0900bb19a850c0a249bede83bb6ed70
56+
runtime-dependency:
57+
registry: mcr.microsoft.com
58+
repository: windows/servercore
59+
tag: ltsc2019
60+
digest: sha256:2bacc4bdc5d1bd805587cb90a2fb2d58d1c775b02df1a19fd221cbfc639ff587
61+
git: {}
62+
63+
64+
Run ID: cf1bun was successful after 5m1s
65+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# escape=`
2+
FROM mcr.microsoft.com/windows/servercore:ltsc2019
3+
4+
# Copy a simple text file into the image
5+
COPY hello.txt C:\hello.txt
6+
7+
# When the container runs, display the contents of hello.txt
8+
CMD ["cmd", "/c", "type C:\\hello.txt && timeout /t 10"]
9+

windows-oci-context/context/hello.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello from Windows container!

0 commit comments

Comments
 (0)