Skip to content

namespacelabs/examples-nsc-build-simple

Repository files navigation

Namespace Cloud Build Example

Build Actions Workflow Build CLI Workflow NS Registry Workflow

This repository shows how to use Namespace Cloud to build a sample Docker container.

Examples

Namespace Cloud CLI

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.

Github Actions

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.

Namespace Cloud Container Registry

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.

Run It Yourself!

  1. Fork this repository;

  2. Enable the GitHub Actions for it;

  3. Configure the GitHub Actions to have write permissions on the repository;

    1. Go to Settings, then Actions and finally General;
    2. Scroll down to Workflow permissions;
    3. Set Read and write permissions option;
  4. Manually run the build workflow;

  5. Pull the image locally!

    docker pull ghcr.io/< your GitHub username >/nsc-django-example:v0.0.1

Community

Join us on Discord for questions or feedback!

About

How to use Namespace Cloud to build a Docker container.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages