HiveBrain v1.2.0
Get Started
← Back to all entries
principledockerMinor

Best Practice for writing DockerFile

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
practicewritingdockerfileforbest

Problem

I have mostly seen people using following type of pipeline steps(it varies, but in general this is the flow of steps I have observed)

Process: clone repo -> build -> test -> create docker image -> push
binary to artifactory -> push image to docker registry

Recently I came across a docker file (multi-stage docker file) which was executing gradle build and test while building image.

I wanted to reach out to this community and check what are the advantages/dis-advantages of having a docker file which does gradle/maven build and test as a part of docker build?

Please Guide

Solution

I don't know if this is a good practice or not, but I usually create 2 docker files.
One just runs the application and the other runs a multi-stage build (including test), the latter is only used by the developer, the former is the one used on CI.

The CI steps depend mostly on what language is the code, what types of tests you want to run, and what process (or development flow) the company use.

For a compiled language (like java or golang):

tests that does not need to build the code (unit tests, SAST..) --> build (the code and the container image if needed) --> tests that need a runnable version of the code (end-to-end) --> artifact repository

For a non compiled language (like php or python):
tests --> tag

Context

StackExchange DevOps Q#14414, answer score: 2

Revisions (0)

No revisions yet.