the fairy tale of the one command build script

26
The fairy tale of the one command build script Tobias Getrost Senior Developer CI/CD GN Hearing

Upload: docker-inc

Post on 21-Jan-2018

268 views

Category:

Technology


1 download

TRANSCRIPT

The fairy tale of the one command build script

Tobias Getrost

Senior Developer CI/CD GN Hearing

Agenda

About me● Since January 2017 working @ GN

● Driving CI and CD in embedded software development

● Software Craftsman

● CI / CD Enthusiast

● Speaker and author

./build.sh

PatternSingle container

# Maven builddocker run -it --rm \

-v "$PWD":/usr/src/myproject \-w /usr/src/myproject \maven:3-jdk-9 mvn clean install

# Gradle builddocker run -it --rm \

-v "$PWD":/usr/src/myproject \-w /usr/src/myproject \openjdk-8-jdk ./gradlew clean build

When to use?● Most tools provided by package

manager

● Seldom changes to the tool chain

● Local builds

Advantages● No modifications to the build script

● Easy to restore build environments for old versions

● Test new version of the tools

Is your Dockerfilegetting too long?

Does changing one toolcause a rebuild of many images?

PatternOne container per tool (chain)

HTML & JS frontend

Backend Generate thumbnails

Buildcontainer

Approaches● Use a CI server to do the plumbing

● Modify your build script to run the containers

pipeline {agent nonestages {

stage('Build') {agent {

docker ‘java:8-jdk'}steps {

sh './gradlew clean build'}

}}

}

To consider● CI pipeline glues together the build steps

○ How to deal with local builds?

○ Alternative: Make single steps accessible from build script

● Can speed up the builds by providing enough computing power on the build server

task genThumbnails(type:Exec) {commandLine "docker run -it --rm -v ${rootDir}:${ws} -w ${ws} " +

"python:2.7 python genThumbnails.py"}

> ./gradlew genThumbnails

tasks.addRule("Pattern: docker<TaskName>: docker") { String taskName ->if (taskName.startsWith("docker")) {

def taskNameToCall = (taskName - 'docker').toLowerCase()def taskToCall = tasks.findByName(taskNameToCall)if (taskToCall && taskToCall instanceof Exec) {def cmd = ['docker', 'run', '--rm', '-v', "${taskToCall.workingDir.name}:${ws}",

'-w', "${ws}", 'python:2.7']cmd.addAll(taskToCall.commandLine)

task(taskName, type: Exec, {commandLine cmd

})}}}

> ./gradlew dockerGenthumbnails

Advantages● Higher modularity

● Testing new versions of a tool is easy

● Higher reuse of existing images

Windows

What about this?

FROM microsoft/windowsservercore

ENV url https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi

RUN $MsiFile = $env:Temp + '\ipython.msi' ; \(New-Object Net.WebClient).DownloadFile($url, $MsiFile) ; \Start-Process msiexec.exe -ArgumentList '/i', $MsiFile, '/quiet', '/norestart',

'/jm' -NoNewWindow -Wait

Installing an MSI… if it supports silent install

Once upon a time devs needed to spend long time before they could do their first build…

… , then they added Docker to their builds and …

… and they developed happily ever after.

[email protected]/profile/Tobias_Getrostwww.linkedin.com/in/tobias-getrosthttps://github.com/getrosttgetrost.org

Tobias Getrost