Replace basic restart with full reconfiguration of container

This commit is contained in:
Daniel_I_Am 2020-08-17 18:13:07 +02:00
parent a540db0efb
commit 98c328c9e2
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84

View File

@ -140,4 +140,23 @@ deploy:
- docker - docker
script: script:
- 'apk add curl jq' - 'apk add curl jq'
- 'curl -X POST $API_URI/api/endpoints/$ENDPOINT_URI/docker/containers/$CONTAINER_ID/restart -H "Authorization: Bearer `curl -X POST $API_URI/api/auth -H "Content-Type: application/json" -d "{\\"Username\\": \\"$API_USER\\", \\"Password\\": \\"$API_PASS\\"}" | jq -r ".jwt"`"' # Sign in with credentials
- 'AUTH_TOKEN="`curl -X POST $API_URI/api/auth -H "Content-Type: application/json" -d "{\\"Username\\": \\"$API_USER\\", \\"Password\\": \\"$API_PASS\\"}" | jq -r ".jwt" | tr -d "\n"`"'
# Update chaosbot:latest image
- 'curl -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH_TOKEN" "$API_URI/api/endpoints/$ENDPOINT_URI/docker/images/create?fromImage=registry.chaoticlogic.us%2Fchaosbot:latest" -H "X-Registry-Auth: eyJzZXJ2ZXJhZGRyZXNzIjoicmVnaXN0cnkuY2hhb3RpY2xvZ2ljLnVzIn0=" --data-raw "{\\"fromImage\\":\\"registry.chaoticlogic.us/chaosbot:latest\\"}"'
# Stop old container
- 'curl -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH_TOKEN" "$API_URI/api/endpoints/$ENDPOINT_URI/docker/containers/$CONTAINER_ID/stop" --data-raw "{}"'
# Rename old container
- 'curl -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH_TOKEN" "$API_URI/api/endpoints/$ENDPOINT_URI/docker/containers/$CONTAINER_ID/rename?name=%2F$CONTAINER_ID-old" --data-raw "{}"'
# Create new container
- 'CONTAINER_CREATION_RESPONSE=`curl -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH_TOKEN" "$API_URI/api/endpoints/$ENDPOINT_URI/docker/containers/create?name=$CONTAINER_ID" --data-raw "{\\"Cmd\\":[],\\"Entrypoint\\":[\\"./ChaosBot\\"],\\"Hostname\\":\\"b47984029a4a\\",\\"Image\\":\\"registry.chaoticlogic.us/chaosbot:latest\\",\\"Labels\\":{},\\"OnBuild\\":null,\\"OpenStdin\\":false,\\"StdinOnce\\":false,\\"Tty\\":false,\\"User\\":\\"\\",\\"Volumes\\":{\\"/App/appsettings.json\\":{}},\\"WorkingDir\\":\\"/App\\",\\"HostConfig\\":{\\"AutoRemove\\":false,\\"Binds\\":[\\"/etc/ChaosBot/appsettings.json:/App/appsettings.json:ro\\"],\\"RestartPolicy\\":{\\"MaximumRetryCount\\":0,\\"Name\\":\\"unless-stopped\\"}},\\"name\\":\\"ChaoticLogicBot\\"}"`'
- 'NEW_CONTAINER_ID=`echo $CONTAINER_CREATION_RESPONSE | jq -r ".Id"`'
- 'NEW_RESOURCE_CONTROL_ID=`echo $CONTAINER_CREATION_RESPONSE | jq -r ".Portainer.ResourceControl.Id"`'
# Connect new container to docker bridge
- 'curl -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH_TOKEN" "$API_URI/api/endpoints/$ENDPOINT_URI/docker/networks/bridge/connect" --data-raw "{\\"Container\\":\\"$NEW_CONTAINER_ID\\"}"'
# Start new container
- 'curl -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH_TOKEN" "$API_URI/api/endpoints/$ENDPOINT_URI/docker/containers/$NEW_CONTAINER_ID/start" --data-raw "{}"'
# Lock down new container
- 'curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH_TOKEN" "$API_URI/api/resource_controls/$NEW_RESOURCE_CONTROL_ID" --data-raw "{\\"AdministratorsOnly\\":true,\\"Public\\":false,\\"Users\\":[],\\"Teams\\":[]}"'
# Delete old container
- 'curl -X DELETE "$API_URI/api/endpoints/$ENDPOINT_URI/docker/containers/$CONTAINER_ID-old?force=true&v=1" -H "Authorization: Bearer $AUTH_TOKEN"'