|
| 1 | +# cf-deploy-dcos |
| 2 | +The repository contains code for `codefresh/cf-deploy-dcos` image building. This image makes an application deployment on DC/OS cluster using application definition json file. |
| 3 | +It takes application deployment template (deployment.tmpl) and generates application deployment json file substituting variables in the template with the the environment variables values then applies the application deployment json file to DC/OS cluster using DC/OS CLI command. |
| 4 | + |
| 5 | + |
| 6 | +# Usage |
| 7 | +In order to use the `codefresh/cf-deploy-dcos` image we need to do the following: |
| 8 | + |
| 9 | +1. Define environment variables in Codefresh pipeline. |
| 10 | + |
| 11 | +- `DCOS_URL` **required** - DC/OS cluster URL |
| 12 | +- `DCOS_CLUSTER_NAME` **required** - DC/OS cluster name |
| 13 | +- `DCOS_CLUSTER_ID` **required** - DC/OS cluster ID |
| 14 | +- `DCOS_DCOS_ACS_TOKEN` **required** - DC/OS cluster existing user's token (make it encrypted) |
| 15 | +- `DCOS_SSL_VERIFY` default is true, if we want to bypass SSL certificate verification - set it to `false` |
| 16 | +- `APP_ID` - application name |
| 17 | +- `IMAGE_NAME` - application image name |
| 18 | +- `IMAGE_TAG` - application image tag |
| 19 | + |
| 20 | +2. Create deployment.tmpl and codefresh.yml files in an application repository at the root level. |
| 21 | + |
| 22 | +``` |
| 23 | +codefresh.yml |
| 24 | +--- |
| 25 | +version: '1.0' |
| 26 | +steps: |
| 27 | + BuildingDockerImage: |
| 28 | + type: build |
| 29 | + image_name: applcation/image |
| 30 | + ... |
| 31 | +
|
| 32 | + PushToRegistry: |
| 33 | + type: push |
| 34 | + candidate: ${{BuildingDockerImage}} |
| 35 | + ... |
| 36 | +
|
| 37 | + DeployToDcos: |
| 38 | + image: codefresh/cf-deploy-dcos:latest |
| 39 | + working_directory: ${{main_clone}} |
| 40 | + commands: |
| 41 | + - /cf-deploy-dcos deployment.tmpl |
| 42 | + environment: |
| 43 | + - DCOS_URL=${{DCOS_URL}} |
| 44 | + - DCOS_CLUSTER_NAME=${{DCOS_CLUSTER_NAME}} |
| 45 | + - DCOS_CLUSTER_ID=${{DCOS_CLUSTER_ID}} |
| 46 | + - DCOS_DCOS_ACS_TOKEN=${{DCOS_DCOS_ACS_TOKEN}} |
| 47 | + - DCOS_SSL_VERIFY=${{DCOS_SSL_VERIFY}} |
| 48 | + - APP_ID=${{APP_ID}} |
| 49 | + - IMAGE_NAME=${{IMAGE_NAME}} |
| 50 | + - IMAGE_TAG=${{IMAGE_TAG}} |
| 51 | +``` |
| 52 | +We define freestyle step (DeployToDcos in the example above) and environment variables the same as in the Codefresh pipeline. |
| 53 | + |
| 54 | +``` |
| 55 | +deployment.tmpl |
| 56 | +
|
| 57 | +{ |
| 58 | + "id": "{{APP_ID}}", |
| 59 | + "instances": 1, |
| 60 | + "cpus": 0.1, |
| 61 | + "mem": 64, |
| 62 | + "container": { |
| 63 | + "type" : "DOCKER", |
| 64 | + "docker": { |
| 65 | + "image": "{{IMAGE_NAME}}:{{IMAGE_TAG}}", |
| 66 | + "forcePullImage": true, |
| 67 | + "privileged": false, |
| 68 | + "network": "BRIDGE", |
| 69 | + "portMappings": [ |
| 70 | + { "hostPort": 80, "containerPort": 8081, "protocol": "tcp", "name": "http"} |
| 71 | + ] |
| 72 | + } |
| 73 | + }, |
| 74 | + "acceptedResourceRoles": [ |
| 75 | + "slave_public" |
| 76 | + ] |
| 77 | +} |
| 78 | +``` |
| 79 | +`APP_ID`, `IMAGE_NAME` and `IMAGE_TAG` variables are just examples. We can parametrise any value in application deployment template depending on our requirements. |
| 80 | +But if we set some parameter `{{PARAMETER}}` in application deployment template we should ensure that this parameter is set both in Codefresh pipeline and in codefresh.yml freestyle step as well. |
| 81 | + |
| 82 | +Notes: we can use already configured DC/OS CLI dcos command to get DC/OS cluster parameters. |
| 83 | +Example: |
| 84 | +``` |
| 85 | +dcos cluster list --attached --json |
| 86 | +
|
| 87 | +[ |
| 88 | + { |
| 89 | + "attached": true, |
| 90 | + "cluster_id": "9d50f776-****-433c-****-ebb01eaafbbc", |
| 91 | + "name": "dcos-master", |
| 92 | + "url": "https://dcos-master.cloudapp.azure.com", |
| 93 | + "version": "1.10.2" |
| 94 | + } |
| 95 | +] |
| 96 | +``` |
| 97 | +``` |
| 98 | +dcos config show core.dcos_acs_token |
| 99 | +
|
| 100 | +eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik9UQkVOakZFTWtWQ09VRTRPRVpGTlRNMFJrWXlRa015Tnprd1JrSkVRemRCTWpBM1FqYzVOZyJ9.ey******** |
| 101 | +``` |
0 commit comments