Hosting Spin Apps in Open Container Initiative (OCI) Registries

Spin Open Container Initiative (OCI) Support

From Spin v0.8.0 onwards, you can store and run Spin applications stored in an OCI compatible registry. Spin developers now have a powerful workflow that enables them to use idiomatic infrastructure tooling, such as GitHub Container Registry (GHCR) or DockerHub, to store, deploy, and share their Spin applications.

Prerequisites

First, follow this guide to install Spin v0.8.0 or later. To ensure you have the correct version, you can check with this command:

$ spin --version

Set Up Your GHCR Instance

To use a GHCR instance, you need to set up authentication. In this tutorial, we will use a personal access token (classic). Follow these steps to generate a personal access token and then use it to sign into your GHCR. You should see the following message to confirm your login attempt to GHCR was successful:

> Login Succeed

Push a Spin App to GHCR

Let’s use this full-stack TypeScript and ReactJS Spin app to walk through this tutorial. If you have a Spin app already feel free to navigate to that directory and skip the step below.

Fork and clone the app GitHub repository:

$ git clone https://github.com/USERNAME/spin-react-fullstack.git

Now, switch to that directory and rebuild the application:

$ cd spin-react-fullstack
$ spin build

Now we’re ready to push the application. Run the spin oci push command (for Spin v0.8.0) or the spin registry push command (for Spin v0.9.0 onwards); to push your application to the registry:

$ spin registry push ghcr.io/USERNAME/spin-react-fullstack:v1
$ spin registry push ghcr.io/USERNAME/spin-react-fullstack:v1

You now have a Spin application stored in your registry. You can see the artifact under packages in the GitHub UI.

Pull a Spin App From GHCR

Now that we’ve successfully pushed a Spin app, let’s see if we can pull it. To do so, run the following command:

$ spin registry pull ghcr.io/USERNAME/spin-react-fullstack:v1
$ spin registry pull ghcr.io/USERNAME/spin-react-fullstack:v1

Run a Spin App From GHCR

Lastly, let’s run this Spin application.

$ spin up -f ghcr.io/USERNAME/spin-react-fullstack:v1
$ spin up --from-registry ghcr.io/USERNAME/spin-react-fullstack:v1

Conclusion

Congratulations on completing this tutorial! You have now successfully built, pushed, pulled, and run a Spin app using GHCR. Behind the scenes, Spin uses OCI artifacts project to distribute Spin apps across container registries. To learn more about how this feature works, take a look at our proposal and the implementation.

Next Steps

  • If you’re interested in shaping how registry support will look in the next version, please share your thoughts in our Discord community

Did we miss something?

Let us know how we can improve this project, or contribute an edit to this page. We really appreciate your feedback, to help us build better tools.