commenting out the legacy code instead of deleting it · pipeline flow with docker compose ......

1

Upload: others

Post on 21-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 2: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Redesigning a pipeline flow with Docker Compose@AlmBrand

Loke Norlin Johannessen

Senior System Specialist

Page 3: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Commenting out the legacy code instead of deleting it

Page 4: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Old setup

Jenkins

• Single instance

• Pinged by Gitlab pipeline

Gitlab

• Build pipeline

Docker Enterprise

• Called by custom script

Page 5: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Old deploy method- custom script -

Page 6: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Old “deploy” pipeline

Page 7: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Jenkins pipeline

Page 8: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

New setup

Page 9: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Base systemsUbuntu

• Minimal/Cloud

• Small iso – under 300mb

vSphere

• On-Prem virtualizasion provider

Gitlab

• CI/CD system

Docker Enterprise

• UCP – Access control

• DTR – Image repository

• Engine – Container engine

Page 10: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Ansible• Configuration management• Used during template generation• Used during deploy of infrastructure

Packer• VMware iso/template generation

Terraform• Infrastructure provisioner

Automation tools

Page 11: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Gitlab repo

Page 12: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 13: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Dockerfile

• TIP: Comment the different stages

• TIP: Specify base image tag ( Do not use latest )

Page 14: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Basic layout

Page 15: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Basic layout

Page 16: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Single job pipeline

Page 17: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 18: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Compose

Page 19: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 20: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Use variables

• TIP: Gitlab CI/CD has a LOT of environmental variables

Page 21: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Lint a Dockerfile

• TIP: Hadolint is an excellent linting tool

Page 22: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Hadolint

Page 23: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

ADD

Page 24: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

TIP: Use COPY instead of ADD

Page 25: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

COPY

Page 26: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

TIP: Environment variables can be defined in a file

Page 27: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

• TIP: Define multiple compose files in .env• TIP: Order of precedence matters• TIP: Use docker-compose config > combined_config.yml

Page 28: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Tip: Set defaults Tip: Mandatory variables

Page 29: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

TIP: Set defaults if ENVs are not definedTIP: Allows you to build/deploy on workstationTIP: Requires docker-engine 18.09

Page 30: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 31: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

• TIP: When installing packages, ensure you specify the version

• TIP: WORKDIR is recommended to use if you need to CD

Page 32: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 33: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

• TIP: scratch is a perfect image to use with golang ( “zero” attack surface )

• TIP: Use “COPY --from” to import ca-certs/trusted-certs into scratch images

Page 34: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

TIP: Use commit-SHA as tags

Page 35: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

• TIP: Add environmentals in compose-files

Page 36: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

• TIP: Environmentals are great in a multistage pipeline ( Dev -> Test -> Prod )

Page 37: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

• TIP: Pushing to a Gitlab or DTR is easy ( We impersonate users and do the push on their behalf with ucp-bundles )

Page 38: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 39: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 40: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

• TIP: Use dive to rate quality of image ( size, wasted space )

Page 41: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 42: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 43: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Tip:Include

pipelines

• TIP: Include/Use centralized gitlab configs for pipelines

Page 44: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old

Tip:local storage

driver

• TIP: The local storage driver is powerful – NFS mount without any plugins

Page 45: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 46: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old
Page 47: Commenting out the legacy code instead of deleting it · pipeline flow with Docker Compose ... Senior System Specialist. Commenting out the legacy code instead of deleting it. Old