|
| 1 | +onf--- |
| 2 | +meta: |
| 3 | + title: Fast deployment of documentation on Serverless Containers with mdbooks |
| 4 | + description: Step-by-step guide to deploy mdbooks on Serverless Containers. |
| 5 | +content: |
| 6 | + h1: Deploying mdbooks on Serverless Containers |
| 7 | + paragraph: |
| 8 | +tags: docker container deploy serverless |
| 9 | +hero: assets/scaleway-umami.webp |
| 10 | +categories: |
| 11 | + - containers |
| 12 | + - container-registry |
| 13 | +dates: |
| 14 | + validation: |
| 15 | + posted: |
| 16 | +--- |
| 17 | + |
| 18 | +Publish modern online books, for product, API documentation, tutorials, course material or anything that requires a clean, easily navigable and customizable presentation. |
| 19 | + |
| 20 | +<Macro id="requirements" /> |
| 21 | + |
| 22 | +- A Scaleway account logged into the [console](https://console.scaleway.com) |
| 23 | +- [Owner](/identity-and-access-management/iam/concepts/#owner) status or [IAM permissions](/identity-and-access-management/iam/concepts/#permission) allowing you to perform actions in the intended Organization |
| 24 | +- Docker installed on your local machine |
| 25 | + |
| 26 | +## Why deploying on Serverless |
| 27 | + |
| 28 | +Serverless products are perfect for cost efficiency with a pay-as-you go model and scales very well. |
| 29 | + |
| 30 | +With zero infrastructure management a lot of tools to integrate in CI/CD environments, `mdbooks` can benefits a lot of Serverless Containers. |
| 31 | + |
| 32 | +## Local setup |
| 33 | + |
| 34 | +Follow [Istallation instructions](https://rust-lang.github.io/mdBook/guide/installation.html) of mdbooks. |
| 35 | + |
| 36 | +Run: |
| 37 | +- `mdbook init my-first-book` in order to create a sample book. |
| 38 | +- `cd my-first-book` |
| 39 | + |
| 40 | +Now you can edit the content of the book to publish. |
| 41 | + |
| 42 | +It's recommanded to test the book using the command: `mdbook test`. |
| 43 | + |
| 44 | +## Prepare Container Registry |
| 45 | + |
| 46 | +<Message type="note"> |
| 47 | + We recommend using Scaleway Container Registry instead of external registries to avoid errors of rate limiting and risks regarding evolutions of CGU and pricing. |
| 48 | +</Message> |
| 49 | + |
| 50 | +1. Create a file named `Dockerfile` in this folder containing the following code: |
| 51 | + |
| 52 | +```dockerfile |
| 53 | +FROM debian:bookworm-slim |
| 54 | + |
| 55 | +WORKDIR /app |
| 56 | + |
| 57 | +# Copy necessary files (add if you have custom files) |
| 58 | +COPY book.toml /app/ |
| 59 | +COPY src/* /app/src/ |
| 60 | + |
| 61 | +# Install mdbooks binary |
| 62 | +RUN apt-get -y update; apt-get -y install curl; |
| 63 | +RUN mkdir /home/mdbooks |
| 64 | +RUN curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.40/mdbook-v0.4.40-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=/home/mdbooks |
| 65 | +ENV PATH="$PATH:/home/mdbooks" |
| 66 | + |
| 67 | +# Serve the book: |
| 68 | +# 0.0.0.0 is required to listen on public interface, otherwise mdbook will only listen for localhost |
| 69 | +# 8080 port is used to match the Serverless Container settings. |
| 70 | +ENTRYPOINT ["mdbook", "serve", "-n", "0.0.0.0", "-p", "8080" ] |
| 71 | +``` |
| 72 | + |
| 73 | +2. Open Container Registry product on Scaleway Console. |
| 74 | +3. Click **Create namespace**. A namespace is used to hold the image. |
| 75 | + |
| 76 | +<Message type="note"> |
| 77 | + A pop-up will appear with informations to log into your Container Registry Namespace. This will allow to push the image later. |
| 78 | +</Message> |
| 79 | + |
| 80 | +4. Create the namespace and save the registry endpoint. It should be something like `rg.fr-par.scw.cloud/<namespace>` |
| 81 | + |
| 82 | +## Build and Push |
| 83 | + |
| 84 | +1. Run the command `docker build -t rg.<region>.scw.cloud/<namespace>/<image_name>:<tag_name> .` |
| 85 | +* **region**: to get this information, check the namespace settings of the namespace you created. |
| 86 | +* **image_name**: use the name you want to identify your image, for example `mdbook`. |
| 87 | +* **tag_name**: use tags to identify the version of your image, for example `v1`. |
| 88 | + |
| 89 | +2. Push the image: |
| 90 | +`docker push rg.<region>.scw.cloud/<namespace>/<image_name>:<tag>` |
| 91 | + |
| 92 | +## Deploy the Serverless Container |
| 93 | + |
| 94 | +1. Create a Serverless Container Namespace. [Link to console](https://console.scaleway.com/containers/namespaces/create) |
| 95 | +2. Configure the Serverless Containers. Important points are: |
| 96 | +* **Image**: Select the Registry namespace, Container and Tag you created before using the dropdowns. |
| 97 | +* **Name**: You can change the default name to use a more meaningful one. |
| 98 | + |
| 99 | +You can keep default values of other parameters and fine-tune them later at anytime without downtime. |
| 100 | + |
| 101 | +3. Click "Deploy container" button and wait few seconds for the deployment. |
| 102 | +4. Congratulation you Serverless Container is deployed an ready :) |
| 103 | + |
| 104 | +## Going further |
| 105 | + |
| 106 | +- Integrate in CI/CD |
0 commit comments