Matthew Clemente
Legacy Infrastructure
Scriptable
Scalable
Containerized
12-Factor App
CI/CD
Microservices
Still don't know how to do this.
¯\_(ツ)_/¯
Bret Fisher, Taking Docker to Production, DockerCon Europe 2017
John Dewey, Experience & Education, 1938
Don't tell me that it's possible without showing me how!
Learning By Doing
Concrete Examples
Stephen Covey, The 7 Habits of Highly Effective People, 1989
.
├── .env
├── .gitlab-ci.yml
├── .secrets
│ ├── cfml.admin.password.dev
│ └── cfml.admin.password.v1
├── app
│ ├── .CFConfig.json
│ ├── box.json
│ ├── server.json
│ └── wwwroot
│ └── index.cfm
├── build
│ ├── cfml
│ │ ├── Dockerfile
│ │ └── config
│ └── deploy-secrets.sh
├── docker-compose.override.yml
├── docker-compose.debug.yml
└── docker-compose.yml
.
├── docker-compose.override.yml
├── docker-compose.debug.yml
└── docker-compose.yml
$ docker-compose up
version: "3.7"
services:
cfml:
image: "registry.gitlab.com/${CI_PROJECT_NAMESPACE}/starter-swarm-coldfusion/cfml:${BUILD_TAG:-latest}"
build:
context: .
dockerfile: ./build/cfml/Dockerfile
environment:
PORT: 8080
SSL_PORT: 8443
cfconfigfile: .CFConfig.json
cfconfig_inspectTemplate: never
secrets:
- cfml.admin.password
ports:
- target: 8080
published: 80
- target: 8443
published: 443
networks:
internal:
driver: overlay
secrets:
cfml.admin.password:
external: true
name: cfml.admin.password.v1
version: "3.7"
services:
cfml:
volumes:
- ./app:/app
environment:
cfconfig_inspectTemplate: always
ports:
- target: 8080
published: 8080
- target: 8443
published: 8443
networks:
internal:
driver: bridge
secrets:
cfml.admin.password:
external: false
file: ./.secrets/cfml.admin.password.dev
docker-compose.override.yml
docker-compose.yml
┻━┻︵ \(°□°)/ ︵ ┻━┻
# Create Docker Droplet
doctl compute droplet create test
--size 1gb
--image docker-18-04
--region nyc1
# List Droplets
doctl compute droplet list
#Delete a Droplet
doctl compute droplet delete 123456
#List SSH Key Ids and Names
doctl compute droplet list --format "ID,Name"
(Official DigitalOcean Command-Line Client)
{CONFIG}
CODE
Adam Wiggins, The Twelve-Factor App, 2017
.env
CI_PROJECT_NAMESPACE=mjclemente
OTHER_SETTING=
FOO=bar
services:
cfml:
image: "registry.gitlab.com/${CI_PROJECT_NAMESPACE}/starter-swarm-coldfusion/cfml:${BUILD_TAG:-latest}"
build:
context: .
dockerfile: ./build/cfml/Dockerfile
environment:
PORT: 8080
SSL_PORT: 8443
cfconfigfile: .CFConfig.json
cfconfig_inspectTemplate: never
CF_ADMINPASSWORD: <<SECRET:cfml.admin.password>>
secrets:
- cfml.admin.password
{
"adminPassword": "${CF_ADMINPASSWORD}",
"adminAllowConcurrentLogin": true,
"adminAllowedIPList": "",
"adminLoginRequired": true,
"adminRDSEnabled": "false",
"adminRDSLoginRequired": "false",
"adminRDSUserIDRequired": true,
"adminRootUserID": "admin",
"adminUserIDRequired": false,
"ajaxDebugWindowEnabled": false,
"allowApplicationVarsInServletContext": false,
"allowExtraAttributesInAttrColl": true,
"applicationMangement": true,
"applicationMaximumTimeout": "2,0,0,0",
"applicationMode": "curr2driveroot",
"applicationTimeout": "2,0,0,0",
(Same behavior in server.json)
secrets:
cfml.admin.password:
external: true
name: cfml.admin.password.v1
secrets:
cfml.admin.password:
external: false
file: ./.secrets/cfml.admin.password.dev
docker-compose.override.yml
docker-compose.yml
version: "3.7"
services:
cfml:
...
environment:
PORT: 8080
SSL_PORT: 8443
cfconfigfile: .CFConfig.json
cfconfig_inspectTemplate: never
CF_ADMINPASSWORD: <<SECRET:cfml.admin.password>>
secrets:
- cfml.admin.password
₍₍ ᕕ( ಠ‿ಠ)ᕗ
.gitlab-ci.yml
before_script:
before_script:
## We're gonna log into the gitlab registry, as that's where these images are stored
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
## 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]
Getting everything set up
.gitlab-ci.yml
before_script:
- [earlier configuration]
## Use git `show` with --format=%ci to get ISO 8601 date
- export COMMIT_TIME=$(git show -s --format=%ci $CI_COMMIT_SHA)
## Use first 10 characters of the datetime (ie: 2019-03-19)
- export COMMIT_TIME_SHORT=$(echo $COMMIT_TIME | head -c10)
- export BUILD_TAG="${COMMIT_TIME_SHORT}_$CI_COMMIT_SHORT_SHA"
.gitlab-ci.yml
deploy:
stage: deploy
only:
- deploy
except:
variables:
- $CI_COMMIT_MESSAGE =~ /Initial commit/i
- $CI_COMMIT_MESSAGE =~ /skip deploy/i
- $CI_COMMIT_MESSAGE =~ /don't deploy/i
.gitlab-ci.yml
build:
stage: build
only:
- deploy
script:
## Build the image, with BUILD_TAG and latest tags
- 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
.gitlab-ci.yml
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 basetest --with-registry-auth
.gitlab-ci.yml
(Zero-config tool to make locally trusted development certificates)
+
Dr. Thomas Fuller, Gnomologia, 1732
Matthew Clemente