Site
Self-host your site deco
Site Deployment (Docker)
The state and configuration of the system are entirely defined in the file system. Thus, the site’s state is self-contained within the file system itself, without the need for communication with external systems by default. However, the site can access databases, SaaS services, or other web services, as implemented by the developer, but this is not a mandatory requirement of the Deco runtime.
To facilitate the deployment process, we offer a simple strategy using a Dockerfile.
Dockerfile
To deploy in Docker, copy the code below to a Dockerfile in the root of your
project. It is necessary to configure at least the environment variable
ENV DECO_SITE_NAME
to reflect the name of your site or project.
Dockerfile Explanation
Here are some important details about the Dockerfile
above, which may need
customization according to your use case:
-
FROM denoland/deno:alpine
- Defines the base Docker image. You can specify an exact version, such as
FROM denoland/deno:2.0.1.
- Defines the base Docker image. You can specify an exact version, such as
-
EXPOSE 8000
- Exposes the port where the application will be available.
-
RUN echo -e ... >> _docker_deps.ts
- Defines the dependencies that will be cached to avoid fetching external packages during execution.
-
RUN deno cache --allow-import --frozen main.ts dev.ts _docker_deps.ts
- Caches the project’s dependencies.
-
ARG GIT_REVISION=1
- Allows defining a build argument to identify project revisions.
-
ENV DECO_SITE_NAME=yoursitename
- Sets an environment variable used to identify the site in the Deco runtime.
-
ENV DENO_DEPLOYMENT_ID=$GIT_REVISION
- Variable used to manage the site’s asset cache, which should be changed with each new build.
-
CMD ["run", "--cached-only", "-A", "--unstable-kv", "main.ts"]
- Command that runs the server with the necessary permissions.
Docker Deployment
To create the Docker image based on your project, run the following command in the root directory:
docker build -t site_image .
If necessary, you can pass the GIT_REVISION
argument to identify a specific
build revision:
docker build --build-arg GIT_REVISION=2 -t site_image .
Finally, create and run the Docker container:
docker run -p 8000:8000 --name site_container site_image
With this, your site will be running in a Docker container, ready for use.
Was this page helpful?