This repository shows how to use Namespace Cloud to build a sample Docker container.
This example uses nsc
CLI to build and push a Docker image to GitHub Container Registry.
name: build-with-cli
on: [push]
permissions:
# Required for requesting the GitHub Token
id-token: write
# Required for pushing images to GitHub Container Registry
packages: write
jobs:
build_with_nscloud:
runs-on: ubuntu-latest
name: Build with Namespace Cloud
steps:
- name: Checkout
uses: actions/checkout@v3
# We are going to push to GH Container Registry
- name: Log in to GitHub registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
# Install CLI and authenticate to Namespace Cloud
- name: Install and configure Namespace Cloud CLI
uses: namespacelabs/nscloud-setup@v0
# Build and push with your Namespace Cloud workspace build cluster
- name: Build and push with Namespace Cloud cluster
run: |
nsc build . -t ghcr.io/${{ github.repository_owner }}/app:latest --push
By default nsc
builds an image of local host platform. To build
a multi-platform image or an image for another platform, --platform
flag can
be used. For example:
name: build-with-cli
on: [push]
permissions:
# Required for requesting the GitHub Token
id-token: write
# Required for pushing images to GitHub Container Registry
packages: write
jobs:
build_with_nscloud:
runs-on: ubuntu-latest
name: Build with Namespace Cloud
steps:
- name: Checkout
uses: actions/checkout@v3
# We are going to push to GH Container Registry
- name: Log in to GitHub registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
# Install CLI and authenticate to Namespace Cloud
- name: Install and configure Namespace Cloud CLI
uses: namespacelabs/nscloud-setup@v0
# Build and push with your Namespace Cloud workspace build cluster
- name: Build and push with Namespace Cloud cluster
run: |
nsc build . -t ghcr.io/${{ github.repository_owner }}/app:latest --push --platform=linux/arm64,linux/amd64
See our GitHub Workflow file for a more concrete example.
This example uses Namespace Cloud Actions to build and push a Docker image to GitHub Container Registry.
name: build-with-actions
on: [push]
permissions:
# Required for requesting the GitHub Token
id-token: write
# Required for pushing images to GitHub Container Registry
packages: write
jobs:
build_with_nscloud:
runs-on: ubuntu-latest
name: Build with Namespace Cloud
steps:
- name: Checkout
uses: actions/checkout@v3
# We are going to push to GH Container Registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Install CLI and authenticate to Namespace Cloud
- name: Install and configure Namespace Cloud CLI
uses: namespacelabs/nscloud-setup@v0
# Setup docker build to use your Namespace Cloud workspace build cluster
- name: Set up Namespace Cloud Buildx
uses: namespacelabs/nscloud-setup-buildx-action@v0
# Run standard Docker's build-push action
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/app:latest
See our GitHub Workflow file for a more concrete example.
This example uses Namespace Cloud Actions to build and push a Docker image to Namespace Cloud Container Registry.
name: build-and-push-ns-registry
on: [push]
permissions:
# Required for requesting the GitHub Token
id-token: write
jobs:
build_with_nscloud:
runs-on: ubuntu-latest
name: Build with Namespace Cloud
steps:
- name: Checkout
uses: actions/checkout@v3
# Install CLI and authenticate to Namespace Cloud
- name: Install and configure Namespace Cloud CLI
id: nscloud # Needed to access its outputs
uses: namespacelabs/nscloud-setup@v0
# Setup docker build to use your Namespace Cloud workspace build cluster
- name: Set up Namespace Cloud Buildx
uses: namespacelabs/nscloud-setup-buildx-action@v0
# Run standard Docker's build-push action
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.nscloud.outputs.registry-address }}/app:latest
See our GitHub Workflow file for a more concrete example.
-
Fork this repository;
-
Enable the GitHub Actions for it;
-
Configure the GitHub Actions to have
write
permissions on the repository;- Go to Settings, then Actions and finally General;
- Scroll down to Workflow permissions;
- Set Read and write permissions option;
-
Manually run the build workflow;
-
Pull the image locally!
docker pull ghcr.io/< your GitHub username >/nsc-django-example:v0.0.1
Join us on Discord for questions or feedback!