Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
Testen mit ContainernDocker für Integrationstests
Stefan Hildebrandtconsulting.hildebrandt.tk
TESTEN MIT CONTAINERNDOCKER FÜR INTEGRATIONSTESTS
/ Stefan Hildebrandt @hildebrandttk
VORTRAG MIT ALLEN BILDERN UNTERCONSULTING.HILDEBRANDT.TK/VORTRAEGE.HTM
0
PERFECT DEVELOPMENTAND TEST
ENVIRONMENT?
NOT SHARED!developerstestersci-jobs
EASY SETUP
FULLY DEFINED
FAST STARTUP
GOOD TURNAROUNDdeveloperstesters
LOW MAINTENANCE
FLEXIBLE SIZINGAs much as neededas little as possible
IN SYNC WITH SOURCE CODE
DO YOU KNOW DOCKER ?
USEFUL DOCKERFEATURES
CONTAINERno virtual machine -> no extra kernelno own init services (syslog, network...)process separation (linux process groups)own network (bridge device, iptables)very low overhead
DOCKER HOSTlocalhostvirtual machineremote host (computing center / cloud service)
IMAGESincremental layersreuse of layersnametag
REGISTRYcentral repository for imagespublic
privatereference impl. /
: Distributed load/store
Docker Hub
V1 V2Docker Hub EnterpriseArtifactorydogestry
IMAGES COMPRESSIONregistry: compressednetwork transfer: compresseddocker host: unpacked
DOCKER NETWORKbriptablesNAT
PORT MAPPINGimages defines possible portsbinding on container creationsyntax: docker -p <HOST-Port>:<CONTAINER-Port>
INTER CONTAINER COMMUNICATIONlinks
extra entries within /etc/hostsdefinition on container creationsyntax: docker --link <other-container-name>:<alias-within-container>
SHARED DIRECTORIESnative (bind) mounthigh performanceimage defines possible mount pointsbinding on container creationsyntax: docker -v <HOST-PATH>:<CONTAINER-PATH>
DATA ONLY CONTAINERcontainer used by other(s) for data storagesyntax: docker --volumes-from <DATA-CONTAINER>
ENVIRONMENT PARAMETERSimage defines possible environment variablesdefinition on container creationsyntax: docker -e "deep=purple"
THAT'S A BIT MUCH!
DOCKER-COMPOSEdefinition of
runtime parametersbuild parameters
live cycle commandsbuildstart, up, kill, stoprm
for full environments
DEVELOPMENT WITHDOCKER
APPLICATION UNDER DEVELOPMENT
REMOTE DEPLOYMENT TO CONTAINER➚ fast setup➚ easy updates➘ remote deployment➘ remote debugging➘ less ide support
DOCKER BUILD DEPLOYMENT➚ fast setup➚ easy updates➚ defined deployment➘ remote deployment➘ remote debugging➘ less ide support➘ bad turnaround
DOUBLE CHECK REQUIRED TIMES AND BENEFIT FORSetupBuildDeploymentRoundtripDebugging
APPLICATION UNDER TESTarquillian tests: prefer embedded containersif not suitable: use same checklist as before
SUPPORT SYSTEMSrelational databasesnosql databasescentralized logging...
INTEGRATION TEST ENVIRONMENTperipheral systemtest double systemsruntime for test toolspre defined test datahint: use only tagged images!hint: commit and push containers after failed test-run
PERIPHERAL SYSTEMbest case: add existing image to docker-composecreate ci job to build tagged application imageexample: docker-petclinic
TEST DOUBLE SYSTEMSsimple, self developed systems
Java EERailsGrailswhat ever
soap ui dummy ($)central $$$ systems
could be proxied with additional credentials, routes, ...don't forget the versions!!!
spring bootdropwizard
PRE DEFINED TEST DATAextra layer on system base containerautomated creationrepeatable builddon't use dump filesput data to a location within container!
easy distributionfast startupfast rollback
JAILERdefined database model
extraction from existing schemadefined-by-hand
extraction of full entitiescustom selects, obfuscating, ...
COPY PRODUCTION (NEAR) DATABASEreal test dataobfuscatereduce to minimumautomate
MYSQLstart mysqld within containercreate tables
mysqldump --no-data <SOURCE_DB>| mysql<TARGET_DB>
select and copy dataSET FOREIGN_KEY_CHECKS=0;mysql -e "<QUERY>" <SOURCE_DB> | mysql<TARGET_DB>SET FOREIGN_KEY_CHECKS=1;
stop mysqld within container
ORACLEstart oracle-xe within containercreate db-linkcopy tablescopy datacopy constraints, views, triggers, ...drop db-linkstop oracle-xeexample
DISTRIBUTE CONTAINERtag with repository-urldocker push <FULL-TAG>docker pull <FULL-TAG>example
RUN CONTAINERexamples
pure dockerdocker-compose
MAVENround about dozen plugins
BuildPublishrun/startfine grained configuration
rhuss/docker-maven-plugin
GRADLEvariable-definitions within "Dockerfile"'slinked multi-container-buildsput maven-artifacts into the container
GRADLE DOCKER PLUGIN BY MATTHIAS GRÜTERuses des docker-cli-client or fokus on building containerssimplebuggy, some open pull requests on github -> needs a newmasterExamples
docker-java
GRADLE DOCKER PLUGIN BY BENJAMIN MUSCHKOsupports only many tasks for creating, tagging, deleting and pushing imagesfor deleting on repositories toomore complex syntax for those tasks
docker-java
ARQUILLIAN-CUBEawaitreuse running containerExample arquillan.xml
DATABASE MIGRATION
TYPICAL TOOLSflywayliquibasedbdeploy
EXECUTION TIMEbuild-time-provisionadditional startup-provision
USECASESdatabase migrationtesting database migrationadd/modify testdata
LOGIN INTO CONTAINERsshnsenter
CONCLUSIONS
PROvery fasteasy distributioneasy handling for users
REQUIREMENTSlinuxdisc spacedisc speednetwork performance
ISSUESProduction Ready Registrycleanupchmod 755 run.sh && ./run.sh --> permission denied withAUFSDownload from 127.0.0.1 without authentication
STEFAN HILDEBRANDT - CONSULTING.HILDEBRANDT.TKBeratung, Coaching und ProjektunterstützungJava EEBuildsysteme gradle und maven/ant-MigrationTestautomatisierungCoach in agilen ProjektenDevOps