Previews

Fast and secure Previews for developers who want rapid feature sharing and iteration.

Sharing your changes with your teammates to get early feedback is a crucial step of software development lifecycle. Traditional workflows expect you to pack your changes in a pull request and wait minutes for the preview to be created. Today, you can use Namespace to spin up an ephemeral preview environment and get a public authenticated URL in less than 6 seconds.

Create a Preview

Let's get started by running a preview with an existing image.

The following starts a new preview, running nginx. The nginx container image has nginx, an http reverse proxy, listening on port 80. We export that port to a public endpoint, using -p 80.

$ nsc run --image nginx -p 80
  Created new ephemeral environment! (id: grijlvs6ciapa).
  More at: https://cloud.namespace.so/01gr490qvbntkjn9jwypnd4g04/cluster/grijlvs6ciapa
  Running "nginx-h96k6"
    Exported 80/tcp as https://4bi2reg-grijlvs6ciapa.fra1.nscluster.cloud

Within a few seconds, Namespace created a fresh ephemeral environment and started nginx in it. Since the preview runs in the cloud, all URLs are already sharable.

Exported endpoints are Internet-facing but require authentication. Whoever has access to the workspace where the ephemeral environment was created in, will also have access to the endpoint.

The first link guides you to an overview of the preview in our Namespace dashboard. You will see the logs directly from the running container when opening the cluster page that hosts your preview (grijlvs6ciapa in the above example).

logs page

By selecting the tab Terminal, you can jump into a root SSH session, right in your browser. Alternatively, you can employ nsc to SSH into the preview.

$ nsc ssh grijlvs6ciapa
> nerdctl ps
CONTAINER ID    IMAGE                                       COMMAND                   CREATED          STATUS    PORTS                    NAMES
feabac8afba3    docker.io/library/nginx@sha256:593dac...    "/docker-entrypoint.…"    2 minutes ago    Up        0.0.0.0:20000->80/tcp    nginx-h96k6
> curl 0.0.0.0:20000
<!DOCTYPE html>
<html><head><title>Welcome to nginx!</title>...</html>

The second link brings you straight to the running application.

nginx preview

If you are not logged in your browser or you are not a member of the preview's workspace, you will see the sign in page. Such as follows.

auth page for preview

Developing with Previews

We will use an example Django app to show how you can use Namespace Previews during development. This app exposes its frontend to port TCP/8000.

Clone the repository locally.

$ git clone git@github.com:namespacelabs/examples-nsc-build-simple.git && \
  cd examples-nsc-build-simple

We are going to build the Docker container using our Builder and push the image to our Workspace private registry. However, any container registry would work just as fine. The --name flag will tag the image with your Workspace's registry repository (nscr.io/8enum0hp1l5ii in our example).

$ nsc build . --name nsc-django-app:v0.0.1 --push
 
  Pushed for linux/amd64:
    nscr.io/8enum0hp1l5ii/nsc-django-app:v0.0.1

Now we are ready to run the preview. We know that the Django app listens to port TCP/8000. So, we are going to tell nsc to expose that port.

$ nsc run --image nscr.io/8enum0hp1l5ii/nsc-django-app:v0.0.1 -p 8000
 
  Created new ephemeral environment! (id: 9a7a07dmi91vo).
  More at: https://cloud.namespace.so/8enum0hp1l5ii/cluster/9a7a07dmi91vo
 
  Running "nsc-django-app-tm63o"
    Exported 8000/tcp as https://q02h2n0-9a7a07dmi91vo.fra1.nscluster.cloud

Behind the scene, Namespace creates an ephemeral environment, starts the container and generates the public URL. The ephemeral environment runs for 30 minutes.

The URL is authenticated. That means only the members of your Workspace are able to open the preview.

If you are logged in and you are a member of the same Workspace, then you will see the Django app preview.

django page preview

If you are not logged in your browser or you are not a member of the preview's workspace, you will see the sign in page. Such as follows.

auth page for preview

Debug the Preview

Container logs are streamed live to our Namespace dashboard. If you open the cluster page that hosts your preview (such as 9a7a07dmi91vo in the above example), you will see the logs directly from the running container.

logs page

What's Next?