{"id":25898439,"url":"https://github.com/upsun/demo-nix-js","last_synced_at":"2025-07-11T10:34:35.015Z","repository":{"id":244452184,"uuid":"815253739","full_name":"upsun/demo-nix-js","owner":"upsun","description":"Upsun composable image demo for JS apps","archived":false,"fork":false,"pushed_at":"2024-07-01T18:55:56.000Z","size":595,"stargazers_count":0,"open_issues_count":2,"forks_count":2,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-03T00:18:39.847Z","etag":null,"topics":["nix","upsun","upsun-example"],"latest_commit_sha":null,"homepage":"https://upsun.com","language":"Astro","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/upsun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-14T17:30:02.000Z","updated_at":"2024-07-16T17:00:42.000Z","dependencies_parsed_at":"2024-06-14T20:27:36.326Z","dependency_job_id":"ef873f06-ed9e-48cc-9916-a6e68f08502a","html_url":"https://github.com/upsun/demo-nix-js","commit_stats":null,"previous_names":["upsun/demo-nix-js"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/upsun/demo-nix-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upsun%2Fdemo-nix-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upsun%2Fdemo-nix-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upsun%2Fdemo-nix-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upsun%2Fdemo-nix-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/upsun","download_url":"https://codeload.github.com/upsun/demo-nix-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upsun%2Fdemo-nix-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264785651,"owners_count":23663813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nix","upsun","upsun-example"],"created_at":"2025-03-03T00:18:45.070Z","updated_at":"2025-07-11T10:34:34.994Z","avatar_url":"https://github.com/upsun.png","language":"Astro","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.upsun.com/\"\u003e\n\u003cimg src=\"utils/logo.svg\" width=\"300px\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/upsun/demo-nix-js/issues\"\u003e\n\u003cimg src=\"https://img.shields.io/github/issues/upsun/demo-nix-js.svg?style=for-the-badge\u0026labelColor=f4f2f3\u0026color=6046FF\u0026label=Issues\" alt=\"Open issues\" /\u003e\n\u003c/a\u003e\u0026nbsp\u0026nbsp\n\u003ca href=\"https://github.com/upsun/demo-nix-js/pulls\"\u003e\n\u003cimg src=\"https://img.shields.io/github/issues-pr/upsun/demo-nix-js.svg?style=for-the-badge\u0026labelColor=f4f2f3\u0026color=6046FF\u0026label=Pull%20requests\" alt=\"Open PRs\" /\u003e\n\u003c/a\u003e\u0026nbsp\u0026nbsp\n\u003ca href=\"https://github.com/upsun/demo-nix-js/blob/main/LICENSE.md\"\u003e\n\u003cimg src=\"https://img.shields.io/static/v1?label=License\u0026message=MIT\u0026style=for-the-badge\u0026labelColor=f4f2f3\u0026color=6046FF\" alt=\"License\" /\u003e\n\u003c/a\u003e\u0026nbsp\u0026nbsp\n\u003cbr /\u003e\u003cbr /\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cstrong\u003eContribute and check out our resources!\u003c/strong\u003e\n\u003cbr /\u003e\n\u003cbr /\u003e\n\u003ca href=\"https://discord.gg/PkMc2pVCDV\"\u003e\u003cstrong\u003eJoin us on Discord\u003c/strong\u003e\u003c/a\u003e\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\n\u003ca href=\"https://upsun.com/\"\u003e\u003cstrong\u003eWebsite\u003c/strong\u003e\u003c/a\u003e\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\n\u003ca href=\"https://upsun.com/features/\"\u003e\u003cstrong\u003eFeatures\u003c/strong\u003e\u003c/a\u003e\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\n\u003ca href=\"https://docs.upsun.com\"\u003e\u003cstrong\u003eDocumentation\u003c/strong\u003e\u003c/a\u003e\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\n\u003ca href=\"https://upsun.com/pricing/\"\u003e\u003cstrong\u003ePricing\u003c/strong\u003e\u003c/a\u003e\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\n\u003ca href=\"https://upsun.com/blog/\"\u003e\u003cstrong\u003eBlog\u003c/strong\u003e\u003c/a\u003e\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\u0026nbsp\n\u003cbr /\u003e\u003cbr /\u003e\n\u003c/p\u003e\n\n\u003c!-- \u003cp align=\"center\"\u003e\n\u003ca href=\"https://console.upsun.com/projects/create-project/?template=https://github.com/upsun/demo-nix-js.git\u0026utm_campaign=deploy_on_up?utm_medium=button\u0026utm_source=event_dotjs\u0026utm_content=event_dotjs\" target=\"_blank\" title=\"Deploy with Upsun\"\u003e\u003cimg src=\"utils/dou-button.svg\" width=\"175px\"\u003e\u003c/a\u003e\n\u003c/p\u003e --\u003e\n\n## About\n\nThis is a simple demo project meant to introduce you to working with Javascript runtimes on [Upsun](https://upsun.com).\n\n## Getting started\n\n1. Visit [the Upsun website](https://auth.upsun.com/register?) to register for a trial account. \n    Complete the information and finish sign up.\n1. Create your first organization where the project will live.\n1. Choose the **Deploy an existing local Git repository** option.\n1. Name the project, and provide a region for it to be deployed. \n    Keep the **Production environment name** as the default `main`.\n    Consider selecting a **Green region** (indicated with a green leaf) where carbon impact is lowest.\n1. Follow the instructions on the resulting screen to:\n    - [Install the Upsun CLI](https://docs.upsun.com/administration/cli.html)\n    - Clone this repository\n\n        ```bash\n        git clone git@github.com:upsun/demo-nix-js.git \u0026\u0026 cd demo-nix-js\n        ```\n    \n    - Connect your local project to Upsun\n\n        ```bash\n        upsun project:set-remote GENERATED_PROJECT_ID\n        ```\n1. Since Upsun configuration has already been committed to the repo, push to Upsun using the CLI:\n\n    ```bash\n    upsun push\n    ```\n\nWhen the activity has completed, you will be able to visit the deployed project from its generated URL, which you can find with the command\n\n```bash\nupsun url\n```\n\n## What is deployed\n\nThis project leverages the Upsun [composable image](https://docs.upsun.com/create-apps/app-reference/composable-image.html) application container syntax, which is built on [Nix](https://nix.dev/) and [Nixpkgs](https://search.nixos.org/packages) under the hood. \n\nIt is organized as to use [Turborepo](https://turbo.build/repo), a high-performance build system that simplifies (for this project) local development.\n\n```bash\n.\n├── .git\n├── .gitignore\n├── .upsun\n│   └── config.yaml\n├── apps\n│   ├── bun\n│   │   └── ...\n│   ├── deno\n│   │   └── ...\n│   ├── main\n│   │   └── ...\n│   └── nodejs\n│       └── ...\n├── utils\n│   └── ...\n├── LICENSE.md\n├── README.md\n├── package-lock.json\n├── package.json\n├── shell.nix\n└── turbo.json\n```\n\nIt is comprised of four [application containers ](https://docs.upsun.com/create-apps.html):\n\n- `bun`: \n\n    - a simple [bun](https://bun.sh/)-based application, deployed with the [`bun` Nix package](https://search.nixos.org/packages?channel=24.05\u0026show=bun\u0026from=0\u0026size=50\u0026sort=relevance\u0026type=packages\u0026query=bun).\n    - configuration to deploy this app can be found under the [`applications.bun_app` key](https://github.com/upsun/demo-nix-js/blob/main/.upsun/config.yaml#L21) in `.upsun/config.yaml`.\n\n- `deno`: \n\n    - a simple [deno](https://deno.com/)-based application, deployed with the [`deno` Nix package](https://search.nixos.org/packages?channel=24.05\u0026show=deno\u0026from=0\u0026size=50\u0026sort=relevance\u0026type=packages\u0026query=deno).\n    - configuration to deploy this app can be found under the [`applications.deno_app` key](https://github.com/upsun/demo-nix-js/blob/main/.upsun/config.yaml#L48) in `.upsun/config.yaml`.\n\n- `nodejs`: \n\n    - a simple [Node.js](https://nodejs.org/en)-based application, deployed with the [`nodejs` Nix package](https://search.nixos.org/packages?channel=24.05\u0026from=0\u0026size=50\u0026sort=relevance\u0026type=packages\u0026query=nodejs).\n    - configuration to deploy this app can be found under the [`applications.nodejs_app` key](https://github.com/upsun/demo-nix-js/blob/main/.upsun/config.yaml#L34) in `.upsun/config.yaml`.\n\n- `main`: \n\n    - a basic [Astro](https://astro.build/) applications, deployed with the [`nodejs` Nix package](https://search.nixos.org/packages?channel=24.05\u0026from=0\u0026size=50\u0026sort=relevance\u0026type=packages\u0026query=nodejs).\n    - configuration to deploy this app can be found under the [`applications.main_app` key](https://github.com/upsun/demo-nix-js/blob/main/.upsun/config.yaml#L3) in `.upsun/config.yaml`.\n\nEach of these applications' configuration can be found in the shared `.upsun/config.yaml` file.\n\nWhen deployed to the [Upsun management console](https://console.upsun.com) they will appear like this:\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"utils/graph.png\" width=\"500px\"\u003e\n\u003c/p\u003e\n\n## Next steps\n\n### 1. Update production resources\n\nUpsun automatically [configures default resources for each application](https://docs.upsun.com/manage-resources/adjust-resources.html) on the production environment (**Main**), which you can view with the CLI command `upsun resources:set`:\n\n```bash\n$ upsun resources:set\nResource configuration for the project YOUR_PROJECT_NAME (PROJECT_ID), environment main (type: production):\n+----------------+------+-----+-------------+-----------+-----------+\n| App or service | Size | CPU | Memory (MB) | Disk (MB) | Instances |\n+----------------+------+-----+-------------+-----------+-----------+\n| bun_app        | 0.5  | 0.5 | 224         |           | 1         |\n| deno_app       | 0.5  | 0.5 | 224         |           | 1         |\n| main_app       | 0.5  | 0.5 | 224         |           | 1         |\n| nodejs_app     | 0.5  | 0.5 | 224         |           | 1         |\n+----------------+------+-----+-------------+-----------+-----------+\n```\n\nYou can reuse this same command to reduce the resources of each application to their minimum sizes:\n\n```bash\n$ upsun resources:set --size '*:0.1' --disk 'database:256' --disk '*_app:0'\n\n...\n\nSummary of changes:\n  App: bun_app\n    CPU: decreasing from 0.5 to 0.1\n    Memory: decreasing from 224 MB to 64 MB\n  App: deno_app\n    CPU: decreasing from 0.5 to 0.1\n    Memory: decreasing from 224 MB to 64 MB\n  App: main_app\n    CPU: decreasing from 0.5 to 0.1\n    Memory: decreasing from 224 MB to 64 MB\n  App: nodejs_app\n    CPU: decreasing from 0.5 to 0.1\n    Memory: decreasing from 224 MB to 64 MB\n  Service: database\n    CPU: decreasing from 0.5 to 0.1\n    Memory: decreasing from 1408 MB to 448 MB\n    Disk: decreasing from 512 MB to 256 MB\n\nAre you sure you want to continue? [Y/n] Y\n```\n\nYou can also increase the number of instances of any application when desired:\n\n```bash\n$ upsun resources:set --count 'main_app:2' --disk 'database:256' --disk '*_app:0'       \n\n...\n\nSummary of changes:\n  App: main_app\n    Instance count: increasing from 1 to 2\n```\n\n\u003e [!NOTE]\n\u003e While the **resource allocation** activity executes on your production environment, view its log by clicking the three vertical dots on the far right side of the component. \n\u003e Notice as that activity runs, that each of the applications is **not** rebuilt (the _Reusing existing build..._ text below). \n\u003e ```bash\n\u003e Configuring resources\n\u003e  Updating 'main_app' resources from 0.5 CPU, 224MB RAM to 0.1 CPU, 64MB RAM.\n\u003e  Updating 'bun_app' resources from 0.5 CPU, 224MB RAM to 0.1 CPU, 64MB RAM.\n\u003e  Updating 'nodejs_app' resources from 0.5 CPU, 224MB RAM to 0.1 CPU, 64MB RAM.\n\u003e  Updating 'deno_app' resources from 0.5 CPU, 224MB RAM to 0.1 CPU, 64MB RAM.\n\u003e\n\u003e Building application 'main_app' (runtime type: generic:2023.1, tree: db728ad)\n\u003e  Reusing existing build for this tree ID\n\u003e\n\u003e Building application 'bun_app' (runtime type: generic:2023.1, tree: 37066a9)\n\u003e  Reusing existing build for this tree ID\n\u003e\n\u003e Building application 'nodejs_app' (runtime type: generic:2023.1, tree: e6f7918)\n\u003e  Reusing existing build for this tree ID\n\u003e\n\u003e Building application 'deno_app' (runtime type: generic:2023.1, tree: 750397e)\n\u003e  Reusing existing build for this tree ID\n\u003e\n\u003e ...\n\u003e\n\u003e ```\n\u003e\n\u003e Above all else, **this** is the principal feature of Upsun.\n\u003e The configuration file `.upsun/config.yaml` enables DevOps workflows and infrastructure-as-code,\n\u003e but it is this - reusable build images that are environment-independent - that allow you to \n\u003e provision truly identical preview environments at all will to test your revisions.\n\u003e\n\u003e **See how in the next section.**\n\nIn the Upsun console, you can view resource consumption over time for each of the containers in the environment's cluster to determine how best resources should be adjusted.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"utils/resources.png\"\u003e\n\u003c/p\u003e\n\n### 2. Local development\n\nThis demo includes two methods for local development. \n\n- [Using local runtimes](#local-runtimes)\n- [Using Nix](#nix)\n\nBoth methods require that you have the [Upsun CLI installed](https://docs.upsun.com/administration/cli.html), and they assume you have already followed the above steps to deploy the project on Upsun.\n\n#### Local runtimes\n\n**Requirements:**\n\n- [Node.js 22](https://nodejs.org/en/download/package-manager)\n- [Deno](https://deno.com/)\n- [Bun](https://bun.sh/)\n\n**Run:**\n\n1. Build the apps:\n\n```bash\n./utils/local.sh\n```\n\n2. Run the local servers:\n\n```bash\nnpm run start\n```\n\n#### Nix\n\nThis project leverages the Upsun [composable image](https://docs.upsun.com/create-apps/app-reference/composable-image.html) application container syntax, which is built on [Nix](https://nix.dev/) and [Nixpkgs](https://search.nixos.org/packages) under the hood. \n\nWe can use Nix to replicate the production environment locally, downloading each runtime in isolation instead of doing so manually as is shown above.\n\n**Requirements:**\n\n- [Nix](https://nixos.org/download/)\n\n**Run:**\n\n1. Build the apps:\n\n```bash\nnix-shell\n```\n\n\u003e [!NOTE]\n\u003e The first time you run this command will take some time, but only on that first time. \n\n2. Cleanup when finished:\n\nExit the Nix shell (Ctrl + C, then Ctrl + D), then run: \n\n```bash\nnix-collect-garbage\n```\n\n### 3. Make a revision\n\nIn your local environment, run the command:\n\n```bash\nupsun environment:branch new-feature main\n```\n\nFollow the prompts. \nThis will create a new environment - which is _an exact clone_ of production, including its data (see the Node.js path (`/nodejs`)) to verify this.\nFeel free to use the [local development](#2-local-development) instructions to make a revision, push to Upsun (`upsun push`), and test in the isolated space using production data.\n\nWhen you're satisfied, feel free to `upsun merge` to promote your revisions into production.\n\nUltimately, this is the workflow that makes Upsun standout amongst other providers. \nWhile you may favor an integration to GitHub or GitLab over this local example, being able to iteratively improve your applications with _true staging environments_ in this way brings you a lot of power. \n\n### 4. Challenge: Set up an integration\n\nYou currently have a workflow where revisions made locally are pushed directly to an Upsun project.\nThat is, an Upsun project is the primary remote for your development work.\n\nIt's more likely that you'll want to integrate the project with a repository on a service like GitHub, building on top of an existing CI/CD workflow. \n\nSee the [documentation](https://docs.upsun.com/integrations/source.html) for more details.\n\n### 5. Do the demo\n\nIf you're looking to understand even more about the Upsun development workflow, follow the steps to spin up the [Upsun Demo Project](https://github.com/platformsh/demo-project/tree/main).\n\n### 6. Join the Community\n\nThere are far more concepts than could be explored in a single demo project, talk, or blog post. \nBut we have some of the best minds in web development and computing ready and excited to help with your side project, experiment, or next big idea.\n\n[Join us on Discord and less us help you get going](https://discord.gg/PkMc2pVCDV)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupsun%2Fdemo-nix-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fupsun%2Fdemo-nix-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupsun%2Fdemo-nix-js/lists"}