There’s no shortage of excitement surrounding Docker. But while many developers are familiar with containers in the abstract (they’ve installed Docker on their machines, watched online courses, and played with images locally), they’re unsure of the concrete steps needed to deploy CFML apps to Swarm.
Since it’s said that you learn more on your first day of production than all the time beforehand, why wait? In this session, we’ll take a API Mashup project from local development to replicated cloud deployment on a multi-node Swarm. Containerizing a small, fun application provides a great opportunity for acquiring real-world knowledge and hands-on experience. At each step in the process, I’ll share the practical approaches I’ve learned, with the goal of removing obstacles, both real and imagined, that prevent ColdFusion developers from using Swarm.
ITB2019 Try This At Home: Building a Personal Docker Swarm - Matt Clemente
1. Try This At HomeTry This At Home
Building a Personal Docker SwarmBuilding a Personal Docker Swarm
Matthew Clemente
@mjclemente
@mjclemente84
blog.mattclemente.com
@mjclemente
2. A Familiar StoryA Familiar Story
» Adobe ColdFusion 10 /11
» Windows Server 2008
» Microsoft IIS
» Rackspace
» FTP Deployments
» Dev Server (in basement)
7. You'll learn more onYou'll learn more on
the first day ofthe first day of
production than theproduction than the
previous two months.previous two months.
Bret Fisher, , DockerCon Europe 2017Taking Docker to Production
17. » Structure my project?
» Minimize divergence between Dev and Prod?
» Use environment variables?
» Manage sensitive information?
» Use a private image registry?
» Tag images properly?
» Add Lucee extensions?
» Configure CI/CD for deployment?
» Monitor with FusionReactor?
» Handle sessions?
» File a tax extension?
How Do I...How Do I...
38. Docker Swarm SecretsDocker Swarm Secrets
» Immutable by design
» Account for rotation
» Account for Dev and Production
» Team conventions are essential
https://docs.docker.com/engine/swarm/secrets/
https://docs.docker.com/compose/composefile/#secrets
41. CI/CD with Gitlab RunnersCI/CD with Gitlab Runners
» Configured via .gitlab-ci.yml
» Run automagically
» Multiple types of runners
» Use a dedicated SSH Key
https://docs.gitlab.com/ee/ci/quick_start/
44. before_script:
before_script:
## We're gonna log into the gitlab registry, as that's where
these images are stored
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN
registry.gitlab.com
## Git needed to get the date from the commit sha
- apk add git
## So we can see what's going on in the logs
- docker info
## setup environment variables
- [configuration continues]
1
2
3
4
5
6
7
8
9
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN
registry.gitlab.com
before_script:1
## We're gonna log into the gitlab registry, as that's where
these images are stored
2
3
## Git needed to get the date from the commit sha4
- apk add git5
## So we can see what's going on in the logs6
- docker info7
## setup environment variables8
- [configuration continues]9
- apk add git
before_script:1
## We're gonna log into the gitlab registry, as that's where
these images are stored
2
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN
registry.gitlab.com
3
## Git needed to get the date from the commit sha4
5
## So we can see what's going on in the logs6
- docker info7
## setup environment variables8
- [configuration continues]9
before_script:
## We're gonna log into the gitlab registry, as that's where
these images are stored
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN
registry.gitlab.com
## Git needed to get the date from the commit sha
- apk add git
## So we can see what's going on in the logs
- docker info
## setup environment variables
- [configuration continues]
1
2
3
4
5
6
7
8
9
Getting everything set up
.gitlabci.yml
https://docs.gitlab.com/ee/ci/yaml/#before_scriptandafter_script
45. Tagging Custom ImagesTagging Custom Images
» Don't just use "latest"
» Combination of date and commit
before_script:
- export COMMIT_TIME=$(git show -s --format=%ci $CI_COMMIT_SHA)
- export COMMIT_TIME_SHORT=$(echo $COMMIT_TIME | head -c10)
- export BUILD_TAG="${COMMIT_TIME_SHORT}_$CI_COMMIT_SHORT_SHA"
1
- [earlier configuration]2
## Use git `show` with --format=%ci to get ISO 8601 date3
4
## Use first 10 characters of the datetime (ie: 2019-03-19)5
6
7
- export COMMIT_TIME=$(git show -s --format=%ci $CI_COMMIT_SHA)
before_script:1
- [earlier configuration]2
## Use git `show` with --format=%ci to get ISO 8601 date3
4
## Use first 10 characters of the datetime (ie: 2019-03-19)5
- export COMMIT_TIME_SHORT=$(echo $COMMIT_TIME | head -c10)6
- export BUILD_TAG="${COMMIT_TIME_SHORT}_$CI_COMMIT_SHORT_SHA"7
- export COMMIT_TIME_SHORT=$(echo $COMMIT_TIME | head -c10)
before_script:1
- [earlier configuration]2
## Use git `show` with --format=%ci to get ISO 8601 date3
- export COMMIT_TIME=$(git show -s --format=%ci $CI_COMMIT_SHA)4
## Use first 10 characters of the datetime (ie: 2019-03-19)5
6
- export BUILD_TAG="${COMMIT_TIME_SHORT}_$CI_COMMIT_SHORT_SHA"7 - export BUILD_TAG="${COMMIT_TIME_SHORT}_$CI_COMMIT_SHORT_SHA"
before_script:1
- [earlier configuration]2
## Use git `show` with --format=%ci to get ISO 8601 date3
- export COMMIT_TIME=$(git show -s --format=%ci $CI_COMMIT_SHA)4
## Use first 10 characters of the datetime (ie: 2019-03-19)5
- export COMMIT_TIME_SHORT=$(echo $COMMIT_TIME | head -c10)6
7
.gitlabci.yml
47. Building Custom ImagesBuilding Custom Images
build:
stage: build
only:
- deploy
script:
## Build the image, with the build tag and the latest tag
- docker build --tag $CONTAINER_IMAGE:$BUILD_TAG --tag
$CONTAINER_IMAGE:latest -f ./build/cfml/Dockerfile .
## List images, so we can confirm success
- docker image ls
## Push with the build tag
- docker push $CONTAINER_IMAGE:$BUILD_TAG
## Push with latest
- docker push $CONTAINER_IMAGE:latest
.gitlabci.yml
49. Stack DeploymentStack Deployment
deploy:
stage: deploy
script:
- [a lot of SSH related config]
## Enable SSH functionality made possible in 18.0.9 to switch
our context to the remote server
- export DOCKER_HOST=ssh://root@${HOST_IP}
## Deploy the stack - registry auth is for gitlab
- docker stack deploy -c docker-compose.yml -c docker-
compose.prod.yml basetest --with-registry-auth
.gitlabci.yml
50. » Swarm's missing UI
» Configuration and management
» Separate from application stack
PortainerPortainer
52. » Required in multi-node Swarms
» Free options
» Provided via (beta) Lucee Extensions
» Paid options are superior
Sessions and CachingSessions and Caching
https://blog.mattclemente.com/2018/08/17/installluceeextensionsoncommandboxdockercontainers.html
55. All things areAll things are
difficult before theydifficult before they
are easy.are easy.
Dr. Thomas Fuller, Gnomologia, 1732
56. Try This At HomeTry This At Home
Building a Personal Docker SwarmBuilding a Personal Docker Swarm
Matthew Clemente
@mjclemente
@mjclemente84
blog.mattclemente.com
@mjclemente