|
| 1 | +# Serverless Jobs for automatic Instance snapshot |
| 2 | + |
| 3 | +This project shows how it's possible to automate tasks using Serverless Jobs. |
| 4 | + |
| 5 | +This example is very simple, it generates snapshots of your desired Instance. |
| 6 | + |
| 7 | +# Set-up |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +- Scaleway Account |
| 12 | +- Docker daemon running to build the image |
| 13 | +- Container registry namespace created, for this example we assume that your namespace name is `jobs-snapshot`: [doc here](https://www.scaleway.com/en/docs/containers/container-registry/how-to/create-namespace/) |
| 14 | + |
| 15 | +## Step 1 : Build and push to Container registry |
| 16 | + |
| 17 | +Serverless Jobs, like Serverless Containers (which are suited for HTTP applications), works |
| 18 | +with Containers. So first, using your terminal reach this folder and run the following commands: |
| 19 | + |
| 20 | +```shell |
| 21 | +# First command is to login to container registry, you can find it in Scaleway console |
| 22 | +docker login rg.fr-par.scw.cloud/jobs-snapshot -u nologin --password-stdin <<< "$SCW_SECRET_KEY" |
| 23 | + |
| 24 | +# Here we build the image to push |
| 25 | +docker build -t rg.fr-par.scw.cloud/jobs-snapshot/jobs-snapshot:v1 . |
| 26 | + |
| 27 | +# Push the image online to be used on Serverless Jobs |
| 28 | +docker push rg.fr-par.scw.cloud/jobs-snapshot/jobs-snapshot:v1 |
| 29 | +``` |
| 30 | + |
| 31 | +Note about Serverless Containers versus Serverless Jobs. As we do not expose a web server and we do not |
| 32 | +require features such as auto-scaling, Serverless Jobs are perfect for this use case. |
| 33 | + |
| 34 | +To check if everyting is ok, on the Console you can verify if your tag is present in Container Registry. |
| 35 | + |
| 36 | +## Step 2: Creating the Job Definition |
| 37 | + |
| 38 | +On Scaleway Console on the following link you can create a new Job Definition: https://console.scaleway.com/serverless-jobs/jobs/create?region=fr-par |
| 39 | + |
| 40 | +1. On Container image, select the image you created in the step before. |
| 41 | +1. You can set the image name to something clear like `jobs-snapshot` too. |
| 42 | +1. For the region you can select the one you prefer :) |
| 43 | +1. Regarding the resources you can keep the default values, this job is fast and do not require specific compute power or memory. |
| 44 | +1. To schedule your job for example every night at 2am, you can set the cron to `0 2 * * *`. |
| 45 | +1. Important: advanced option, you need to set the following environment variables: |
| 46 | + |
| 47 | +- `INSTANCE_ID`: grab the instance ID you want to create snapshots from |
| 48 | +- `INSTANCE_ZONE`: you need to give the ZONE of you instance, like `fr-par-2` |
| 49 | +- `SCW_ACCESS_KEY`: your access key |
| 50 | +- `SCW_SECRET_KEY`: your secret key |
| 51 | +- `SCW_DEFAULT_ORGANIZATION_ID`: your organzation ID |
| 52 | + |
| 53 | +1. Click "create job" |
| 54 | + |
| 55 | +## Step 3: Run the job |
| 56 | + |
| 57 | +On your created Job Definition, just click the button "Run Job" and within seconds it should be successful. |
| 58 | + |
| 59 | +# Possible improvements |
| 60 | + |
| 61 | +You can exercice by adding the following features: |
| 62 | + |
| 63 | +- Instead of managing a single instance, make it account wide |
| 64 | +- Add disk backups |
| 65 | +- Add alerts if something goes wrong |
| 66 | + |
| 67 | +# Additional content |
| 68 | + |
| 69 | +- [Jobs Documentation](https://www.scaleway.com/en/docs/serverless/jobs/how-to/create-job-from-scaleway-registry/) |
| 70 | +- [Other methods to deploy Jobs](https://www.scaleway.com/en/docs/serverless/jobs/reference-content/deploy-job/) |
| 71 | +- [Secret key / access key doc](https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/) |
| 72 | +- [CRON schedule help](https://www.scaleway.com/en/docs/serverless/jobs/reference-content/cron-schedules/) |
0 commit comments