https://github.com/lazauk/oras-ociartifact-cli
Generating OCI Artifact in GitHub Container Registry (GHCR) and building a custom Web container image with ORAS and Docker CLI clients.
https://github.com/lazauk/oras-ociartifact-cli
artifact cli container docker ghcr github-actions nginx oci open-container-initiative oras registry
Last synced: 2 months ago
JSON representation
Generating OCI Artifact in GitHub Container Registry (GHCR) and building a custom Web container image with ORAS and Docker CLI clients.
- Host: GitHub
- URL: https://github.com/lazauk/oras-ociartifact-cli
- Owner: LazaUK
- License: mit
- Created: 2025-01-10T23:32:54.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-01-12T21:46:33.000Z (4 months ago)
- Last Synced: 2025-01-20T08:13:56.939Z (4 months ago)
- Topics: artifact, cli, container, docker, ghcr, github-actions, nginx, oci, open-container-initiative, oras, registry
- Language: Dockerfile
- Homepage:
- Size: 262 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ORAS and Docker CLI: Building Custom Images from OCI Artifacts
This guide walks you through generating an **OCI artifact** with the **ORAS CLI** client and then building a customised Docker image of an Nginx web service from that artifact. It includes a sample tarball and Dockerfile to facilitate end-to-end testing, from creating an OCI artifact to deploying a fully functional Web site.
> [!NOTE]
> - An [Open Container Initiative (OCI)](https://opencontainers.org/) artifact is a standardised, portable and secure way to package and distribute software.
> - [ORAS](https://oras.land/) enables distribution of artifacts across OCI-compliant registries, like GitHub Container Registry (GHCR).## Table of Contents
* [Step 1: Create an OCI Artifact](#step-1-create-an-oci-artifact)
* [Step 2: Build a Docker Image](#step-2-build-a-docker-image)
* [Step 3: Deploy a Web site](#step-3-deploy-a-web-site)## Step 1: Create an OCI Artifact
1. Install ORAS client as described [here](https://oras.land/docs/installation/).
2. Create a **personal access token** (PAT) in GiHub's `Settings -> Developer Settings -> Personal Access Tokens -> Tokens (classic)` section. You'll need to allow _read_, _write_ and _delete packages_ permissions in your PAT.
3. Setup environment variables:
``` PowerShell
set GHCR_USER=
set GHCR_TOKEN=ghp_
set GHCR_REPO=
```
4. Login to GHCR with ORAS client:
``` PowerShell
oras login -u %GHCR_USER% -p %GHCR_TOKEN% ghcr.io
```
5. Push tarball and Dockerfile to GHCR as OCI artifact:
``` PowerShell
oras.exe push ghcr.io/%GHCR_USER%/%GHCR_REPO%:v1 demopage.tar.gz:application/x-tar Dockerfile:text/plain
```
6. You can verify that the OCI artifact was created successfully by fetching its manifest file:
``` PowerShell
oras manifest fetch --pretty ghcr.io/%GHCR_USER%/%GHCR_REPO%:v1
```
> [!TIP]
> This guide assumes you're using Windows 11. Refer to the relevant documentation for specific instructions on setting environment variables on different platforms.## Step 2: Build a Docker Image
1. Download the OCI artifact from GHCR:
``` PowerShell
oras pull -o ./download ghcr.io/%GHCR_USER%/%GHCR_REPO%:v1
```
2. Login to GHCR with Docker CLI:
``` PowerShell
docker login ghcr.io -u %GHCR_USER% -p %GHCR_TOKEN%
```
3. Build a Docker image from the downloaded OCI artifact:
``` PowerShell
docker build -t ghcr.io/%GHCR_USER%/%GHCR_REPO%:latest ./download
```
4. Publish newly built Docker image on GHCR:
``` PowerShell
docker push ghcr.io/%GHCR_USER%/%GHCR_REPO%:latest
```## Step 3: Deploy a Web site
1. Launch a container by pulling the latest version of the Docker image from GHCR:
``` PowerShell
docker run -d --name DemoSite -p 8080:80 ghcr.io/%GHCR_USER%/%GHCR_REPO%:latest
```
2. Test Web site by opening [this URL](http://localhost:8080) locally.
