|
| 1 | +# Rust hello world |
| 2 | + |
| 3 | +This example demonstrates the deployment of a simple rust http service on Scaleway Serverless Containers. |
| 4 | + |
| 5 | +This can be useful if you come from Serverless Functions and you need to install specific dependencies on your system. |
| 6 | + |
| 7 | +For this example, we will use the CLI to deploy the container, but you can use [other methods](https://www.scaleway.com/en/docs/serverless/containers/reference-content/deploy-container/). |
| 8 | +You can also use the CLI directly from Scaleway console without having to use your credentials. |
| 9 | + |
| 10 | +## Workflow |
| 11 | + |
| 12 | +Here are the different steps we are going to proceed: |
| 13 | + |
| 14 | +- Quick set-up of Container Registry to host our rust container |
| 15 | +- Deploy the Serverless Container |
| 16 | +- Test the container |
| 17 | + |
| 18 | +## Deployment |
| 19 | + |
| 20 | +### Requirements |
| 21 | + |
| 22 | +To complete the actions presented below, you must have: |
| 23 | +- installed and configured the [Scaleway CLI](https://www.scaleway.com/en/docs/developer-tools/scaleway-cli/quickstart/) |
| 24 | +- installed [Docker](https://docs.docker.com/engine/install/) to build the image |
| 25 | + |
| 26 | +### Building the image |
| 27 | + |
| 28 | +1. Run the following command in a terminal to create Container Registry namespace to store the image: |
| 29 | + |
| 30 | + ```bash |
| 31 | + scw registry namespace create name=hello-rust |
| 32 | + ``` |
| 33 | + |
| 34 | + The registry namespace information displays. |
| 35 | + |
| 36 | +1. Copy the namespace endpoint (in this case, `rg.fr-par.scw.cloud/hello-rust`). |
| 37 | + |
| 38 | +1. Log into the Container Registry namespace you created using Docker: |
| 39 | + |
| 40 | + ```bash |
| 41 | + docker login rg.fr-par.scw.cloud/hello-rust -u nologin --password-stdin <<< "$SCW_SECRET_KEY" |
| 42 | + ``` |
| 43 | + |
| 44 | + At this point, you have correctly set up Docker to be able to push your image online. |
| 45 | + |
| 46 | +1. In a terminal, access this directory (containing the Dockerfile), and run the following command to build the image: |
| 47 | + |
| 48 | + ```bash |
| 49 | + docker build -t crabnet:v1.0.0 . |
| 50 | + ``` |
| 51 | + |
| 52 | +1. Tag and push the image to the registry namespace: |
| 53 | + |
| 54 | + ```bash |
| 55 | + docker tag crabnet:v1.0.0 rg.fr-par.scw.cloud/hello-rust/crabnet:v1.0.0 |
| 56 | + docker push rg.fr-par.scw.cloud/hello-rust/crabnet:v1.0.0 |
| 57 | + ``` |
| 58 | + |
| 59 | +### Deploying the image |
| 60 | + |
| 61 | +In a terminal, run the following command to create a Serverless Containers namespace: |
| 62 | + |
| 63 | + ```bash |
| 64 | + scw container namespace create name=crabnet |
| 65 | + ``` |
| 66 | + The namespace information displays. |
| 67 | + |
| 68 | +1. Copy the namespace ID. |
| 69 | + |
| 70 | +1. Run the following command to create and deploy the container: |
| 71 | + |
| 72 | + ```bash |
| 73 | + scw container container create namespace-id=<PREVIOUS_NAMESPACE_ID> name=crabnet registry-image=rg.fr-par.scw.cloud/hello-rust/crabnet:v1.0.0 |
| 74 | + ``` |
| 75 | + The container information displays. |
| 76 | + |
| 77 | +1. Copy the DomainName (endpoint) to test your container, you can put the endpoint in your web browser for testing. |
0 commit comments