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
│ │ └── extensions
│ │ └── extension-loganalyzer-2.3.2.16.lex
│ └── deploy-secrets.sh
├── docker-compose.override.yml
├── docker-compose.prod.yml
└── docker-compose.yml
.
├── docker-compose.override.yml
├── docker-compose.prod.yml
└── docker-compose.yml
$ docker-compose up
$ docker-compose \
-f docker-compose.yml \
-f docker-compose.prod.yml \
up
# Works if not dependent on Swarm features
docker stack deploy \
-c docker-compose.yml \
-c docker-compose.prod.yml \
test
# For Swarm deployments
version: "3.7"
services:
cfml:
image: "registry.gitlab.com/${CI_PROJECT_NAMESPACE}/starter-swarm-cfml/cfml:${BUILD_TAG:-latest}"
build:
context: .
dockerfile: ./build/cfml/Dockerfile
environment:
PORT: 8080
SSL_PORT: 8443
cfconfigfile: .CFConfig.json
cfconfig_inspectTemplate: never
secrets:
- source: cfml.admin.password
target: 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)
.env
CI_PROJECT_NAMESPACE=mjclemente
OTHER_SETTING=
FOO=bar
version: "3.7"
services:
cfml:
image: "registry.gitlab.com/${CI_PROJECT_NAMESPACE}/starter-swarm-cfml/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:
- source: cfml.admin.password
target: cfml.admin.password
{
"adminPassword":"${CF_ADMINPASSWORD}",
"applicationListener":"modern",
"applicationMode":"curr2root",
"applicationTimeout":"1,0,0,0",
"cacheDefaultFile":"",
"cacheDefaultFunction":"",
"cacheDefaultHTTP":"",
"cacheDefaultInclude":"",
"cacheDefaultObject":"object",
"cacheDefaultQuery":"",
"cacheDefaultResource":"",
"cacheDefaultTemplate":"",
"cacheDefaultWebservice":"",
"caches":{},
"CGIReadOnly":"true",
"clientCookies":"true",
"clientManagement":"false",
"clientTimeout":"90,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:
- source: cfml.admin.password
target: 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 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]
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 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
.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 -c docker-compose.prod.yml basetest --with-registry-auth
.gitlab-ci.yml
(Zero-config tool to make locally trusted development certificates)
+
Dr. Thomas Fuller, Gnomologia, 1732
Matthew Clemente