-
Notifications
You must be signed in to change notification settings - Fork 260
feat(containers): mdbook tutorial #3856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8b3b1df
feat(containers): mdbook tutorial
thomas-tacquet b81f031
Merge branch 'main' into serverless-containers-mdbook
thomas-tacquet 544a217
polish text
thomas-tacquet 6f73431
syntax
thomas-tacquet 567b509
Apply suggestions from code review
thomas-tacquet 667fdc8
Apply suggestions from code review
thomas-tacquet c167ce6
indent
thomas-tacquet fdb0b70
docs(srv): documentation review
SamyOubouaziz 63611ee
docs(srv): update
SamyOubouaziz 3bd83d9
docs(srv): update
SamyOubouaziz 537bd41
docs(srv): fix 404s
SamyOubouaziz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
tutorials/deploy-mdbooks-serverless-containers/index.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| --- | ||
| meta: | ||
| title: Fast deployment of documentation on Serverless Containers with mdBook | ||
| description: Step-by-step guide to deploy mdBooks on Scaleway Serverless Containers. | ||
| content: | ||
| h1: Fast deployment of documentation on Serverless Containers with mdBook | ||
| paragraph: Step-by-step guide to deploy mdBooks on Scaleway Serverless Containers. | ||
| tags: docker container deploy serverless mdbook documentation | ||
| categories: | ||
| - containers | ||
| - container-registry | ||
| dates: | ||
| validation: 2024-10-30 | ||
| posted: 2024-10-30 | ||
| --- | ||
|
|
||
| [mdBook](https://rust-lang.github.io/mdBook/) lets you publish modern online books, for product, API documentation, tutorials, course material or anything that requires a clean, easily navigable, and customizable presentation. | ||
|
|
||
| This tutorial uses `mdbook` to publish simple documentation but the main goal of this tutorial is to show how simple it is to pick a project, package it inside an image, and deploy it on Serverless Containers. | ||
|
|
||
| <Macro id="requirements" /> | ||
|
|
||
| - A Scaleway account logged into the [console](https://console.scaleway.com) | ||
| - [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 | ||
| - [Docker](https://docs.docker.com/engine/install/) installed on your local machine | ||
|
|
||
| ## Why deploy on a Serverless infrastructure? | ||
|
|
||
| Serverless products are perfect for cost efficiency with a pay-as-you-go model, and scale very well. | ||
|
|
||
| With zero infrastructure management and many tools to integrate in CI/CD environments, an `mdBook` deployment is well suited to Serverless Containers. | ||
|
|
||
| ## Setting up mdBook locally | ||
|
|
||
| 1. Follow the [installation instructions](https://rust-lang.github.io/mdBook/guide/installation.html) of mdBook. | ||
|
|
||
| 2. Run the following command to create a sample book: | ||
| ``` | ||
| mdbook init my-first-books | ||
| ``` | ||
|
|
||
| 3. Run the following command to access the folder created by the previous `init` command: | ||
| ``` | ||
| cd my-first-book | ||
| ``` | ||
|
|
||
| 4. Optionally, you can edit the content of the book to publish. | ||
|
|
||
| 5. Test the book using the command below: | ||
| ``` | ||
| mdbook test | ||
| ``` | ||
|
|
||
| ## Preparing the Container Registry | ||
|
|
||
| <Message type="note"> | ||
| We recommend using [Scaleway Container Registry](/containers/container-registry/) instead of external registries to avoid rate limiting errors, and risks linked to CGU and pricing changes. | ||
| </Message> | ||
|
|
||
| 1. Create a file named `Dockerfile` in the previously created folder, and add the following code to it: | ||
|
|
||
| ```docker | ||
| FROM debian:bookworm-slim | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy the necessary files (add your custom files here) | ||
| COPY book.toml /app/ | ||
| COPY src/* /app/src/ | ||
|
|
||
| # Install the mdbooks binary | ||
| RUN apt-get -y update; apt-get -y install curl; | ||
| RUN mkdir /home/mdbooks | ||
| 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 | ||
| ENV PATH="$PATH:/home/mdbooks" | ||
|
|
||
| # Serve the book | ||
| # 0.0.0.0 is required to listen on public interface, otherwise mdbook will only listen for localhost | ||
| # 8080 port is used to match the Serverless Container settings. | ||
| ENTRYPOINT ["mdbook", "serve", "-n", "0.0.0.0", "-p", "8080" ] | ||
| ``` | ||
|
|
||
| 2. Open the Scaleway console in a web browser, and navigate to the [Container Registry](https://console.scaleway.com/containers/). | ||
|
|
||
| 3. Click **+ Create namespace**. [Namespaces](/containers/container-registry/concepts/#namespace) allow you to easily manage the images stored in your Container Registry. | ||
|
|
||
| 4. Enter a name for your namespace, or keep the automatically generated one, then click **Create namespace**. | ||
|
|
||
| <Message type="note"> | ||
| For more information on creating a Container Registry namespace, refer to [the dedicated documentation](/containers/container-registry/how-to/create-namespace/). | ||
| </Message> | ||
|
|
||
| ## Building and pushing the image | ||
|
|
||
| <Message type="note"> | ||
| Remember to replace the placeholders with the corresponding values in the steps below. | ||
| </Message> | ||
|
|
||
| 1. Run the following command in a terminal to sign in to your Container Registry namespace: | ||
| ``` | ||
| docker login rg.fr-par.scw.cloud/<namespace_name> -u nologin --password-stdin <<< "$SCW_SECRET_KEY" | ||
| ``` | ||
| The message `Login Succeeded` appears once you are signed in. | ||
|
|
||
| 2. Run the command below to build and tag your image locally. | ||
|
|
||
| ``` | ||
| docker build -t rg.<region>.scw.cloud/<namespace_name>/<image_name>:<tag_name> . | ||
| ``` | ||
|
|
||
| * The **region** and **namespace_name** can be found in the **Namespace settings** tab of the namespace you created. | ||
| * **image_name**: use the name you want to identify your image, such as `my-mdbook`. | ||
| * **tag_name**: use tags to identify the version of your image, such as `v1`. | ||
|
|
||
| 3. Run the command below to push the image to the Scaleway Container Registry: | ||
| ``` | ||
| docker push rg.<region>.scw.cloud/<namespace>/<image_name>:<tag> | ||
| ``` | ||
|
|
||
| ## Deploying the Serverless Container | ||
|
|
||
| 1. In the [Serverless Containers](https://console.scaleway.com/containers/namespaces/) section of the Scaleway console, click **+ Create namespace**. | ||
|
|
||
| 2. Enter a name for your namespace, or keep the automatically generated one, then click **Create namespace and add container**. | ||
|
|
||
| 3. Select your image from the registry: | ||
| * Select the **Scaleway Container Registry**. | ||
| * From the drop-down menu, select the **registry namespace** previously created. | ||
| * Enter the **port** previously configured in the Dockerfile (`8080` by default) | ||
| * From the drop-down menus, select the **container** and **tag** you created before using the dropdown lists. | ||
| * **Name**: You can change the default name to use a more meaningful one. | ||
|
|
||
| 4. Enter a name for your Serverless Container, or keep the automatically generated one. | ||
|
|
||
| 5. Keep the default **resources** and **scaling** values. You can fine-tune them later without any downtime. | ||
|
|
||
| 3. Click **Deploy container** to proceed. The initial deployment of your container can take up to a few minutes. | ||
|
|
||
| Your Serverless Container is deployed and ready. You can access it via its **endpoint**. | ||
|
|
||
| ## Going further | ||
|
|
||
| * [Monitor logs and metrics](/serverless/containers/how-to/monitor-container/) of your container. | ||
| * [Add a custom domain](/serverless/containers/how-to/add-a-custom-domain-to-a-container/) to your container. | ||
| * Explore [other methods](/serverless/containers/reference-content/deploy-container/) to deploy your container. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.