Skip to content

Deployment

This section attempts to talk about deployment strategies for your Sodacore application.

Building your application

Ensure your build script will build the project as you want, for libraries that can be imported, we use tsc as it generates the type definitions, and is widely supported. You can always use bun build if you want to use Bun's bundler, but it does not generate type definitions without some extra configuration, additionally to this, if you have a project that uses workers, then Bun's bundler will not output separate files (it will inline them), so you may want to use tsc anyway to deal with this, or setup multiple entrypoints so that each worker is built separately, but this usually requires some work arounds. Personally, I just use tsc for everything.

Docker

You can easily dockerise your application, here is a simple example of a Dockerfile that you can use:

dockerfile
FROM oven/bun:latest
WORKDIR /app
RUN apt-get update -y && apt-get install -y openssl;
COPY . .
EXPOSE 8080
CMD ["bun", "start"]

Please note that you are expected to have already built your application before building the Docker image, so ensure you build the application first, before building your image.

Note: If you use Prisma ORM (and honestly most ORMs) you will need to keep Node+NPM installed due to a lot of these libraries using subcommands within NPM scripts, my suggestion would be to have a different place for dealing with your database migrations, awaiting the day that Prisma supports Bun natively. Noted Issue.

Nginx

If you intend to use Nginx as a reverse proxy, regardless of your deployment strategy, here is a simple example of an Nginx configuration that you can use:

plaintext
server {
	listen 80;
	root /var/www/html;
	index index.html;
	server_name <domain>.<tld>;

	location / {
		proxy_pass              http://<host>:<port>;
		proxy_bind              $remote_addr                    transparent;
		proxy_set_header        Host                            $host;
		proxy_set_header        X-Real-IP                       $remote_addr;
		proxy_set_header        X-Forwarded-for                 $remote_addr;
		port_in_redirect        off;
		proxy_connect_timeout   300;
	}
}

I would highly suggest using https, you can easily achieve this using Certbot to generate free SSL certificates from Let's Encrypt.

Released under the Apache-2.0 License.