commenting out the legacy code instead of deleting it · 2019-06-28 · packer •vmware...

45

Upload: others

Post on 12-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo
Page 2: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

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 · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Commenting out the legacy code instead of deleting it

Page 4: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

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 · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Old deploy method

- custom script -

Page 6: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Old “deploy” pipeline

Page 7: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Jenkins pipeline

Page 8: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

New setup

Page 9: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Base systems

Ubuntu

• 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 · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

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 · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Gitlab repo

Page 12: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo
Page 13: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

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 · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Basic layout

Page 15: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Basic layout

Page 16: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Single job pipeline

Page 17: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo
Page 18: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Compose

Page 19: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo
Page 20: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Use variables

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

Page 21: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Lint a Dockerfile

• TIP: Hadolint is an excellent linting tool

Page 22: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Hadolint

Page 23: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

ADD

Page 24: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

TIP: Use COPY instead of ADD

Page 25: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

COPY

Page 26: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

TIP: Environment variables can be defined in a file

Page 27: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

• 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 · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Tip: Set defaults Tip: Mandatory variables

Page 29: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

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 · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo
Page 31: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

• 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 · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo
Page 33: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

• 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 · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

TIP: Use commit-SHA as tags

Page 35: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

• TIP: Add environmentals in compose-files

Page 36: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

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

Page 37: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

• 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 · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo
Page 39: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo
Page 40: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

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

Page 41: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo
Page 42: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo
Page 43: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

Tip:

Include pipelines

• TIP: Include/Use centralized gitlab configs for pipelines

Page 44: Commenting out the legacy code instead of deleting it · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo

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 · 2019-06-28 · Packer •VMware iso/template generation Terraform •Infrastructure provisioner Automation tools. Gitlab repo