Repository navigation
refactor: Revise Dockerfile - #2305
polarathene wants to merge 7 commits into
Conversation
HereDoc (EOF) feature (avoids needing `&& \`) requires BuildKit: https://docs.docker.com/engine/reference/builder/#here-documents
- `--no-cache` implies `--update` (aka `apk update`) while not storing the cache to disk, so no need to manually cleanup the cache with `rm -rf` afterwards. - `--upgrade` updates existing dependencies of packages.
- A group will implicitly be created with the same value as the user. `addgroup testssl` and `-G testssl` are not needed. - Gecos data (`-g "testssl user"`) doesn't appear relevant to the project to be required? Default (`Linux User,,,`) should be fine. - With the HereDoc usage, an inline comment provides additional context.
If local folder ownership is for example `644` it will fail to handle the `COPY` regardless (while `744` would work). Creating the directory with higher permissions in the container does not appear to help.
- `git` isn't needed in the image. - Alpine 3.17 does a major version upgrade of OpenSSL to 3.x, while keeping the 1.1.x version may be beneficial? (can perform better)
|
@polarathene : I appreciate -- really do -- your PR to improve matters. But, gosh, this is a long one with lots of changes. As mentioned in Thus I am closing this. Happy to consider smaller bites served to me. |
This comment was marked as resolved.
This comment was marked as resolved.
|
All changes proposed in this PR have now been raised as separate PRs or issues (to avoid dealing with conflicts). The only exception is the HereDoc (EOF) feature for a nicer If there is interest in this, let me know and I'll raise an issue or PR for it as well (specific commit). |
Summary
PR motivated by discussion in https://github.com/drwetter/testssl.sh/issues/2299#issuecomment-1408253127
Beyond updating the base image version, I've submitted some improvements:
RUNis much simpler now. Using the HereDoc feature could be dropped if you prefer.docker-mailserverhas been using using since Oct 2022 without any problems with our user base (most just use the built image we distribute - unless they're contributing, where ourMakefilehandles theDOCKER_BUILDKIT=1ENV).openssl1.1-compat.openssl1.1-compat): 12.6MBCOPY: 14MBCommit Overview
RUNchaining with&& \by using HereDoc featureHereDoc (with EOF marker) feature avoids needing
&& \requires BuildKit during build (eitherDOCKER_BUILDKIT=1 docker buildor by usingbuildx).COPYby better leveraging.dockerignorepatterns--no-cacheimplies--update(akaapk update) while not storing the cache to disk, so no need to manually cleanup the cache withrm -rfafterwards.--upgradeupdates existing dependencies of packages.addgroup testssland-G testsslare not needed.-g "testssl user") doesn't appear relevant to the project to be required? Default (Linux User,,,) should be fine.mkdirIf local folder ownership is for example
644it will fail to handle theCOPYregardless (while744would work). Creating the directory with higher permissions in the container does not appear to help.git(7MB) addopenssl1.1-compat(4MB)gitisn't needed in the image.3.x, while keeping the1.1.xversion may be beneficial? (can perform better)Image history
Just for the benefit of not having to go through git history :)
muslinstead ofglibc).Packages
drilladded for the DNS lookups withlibidnincluded to support IDN (Internationalized Domain Names) lookups with drill.procpsadded forps(commit from Debian base also dropped other DNS clients in favour ofdrill).socatis also related to supporting "STARTTLS injection" (full PR).openssl(originally for1.1.1g) was also added to support "STARTTLS injection".openssl1.1-compatadded in this PR itself, was found to perform better than the newer3.xseries (introduced by Alpine 3.17) which may matter for reducing CI / test feedback times. It can be used via--openssl /usr/bin/openssl1.1.xxdfor better performance and debugging support.coreutils(approx 9MiB in weight) to replace BusyBox packages, notably for better supportingdate -d.curladded for--phone-outchecks.Further consideration
The PR presently only covers the
3.1devbranchDockerfile. If you're happy with the proposed changes theDockerfile.gitcan be updated and then an equivalent PR can be opened for3.0branch.mkdirwas dropped as despite original reasoning with750permission and ownership, theCOPY --chownensures thetestssluser is fine?apk upgradebeforeapk add. Personally I'm not sure what the value of that is, since generally the base image should reflect the latest updates at the time of build.3.0image was last built over 2 months ago. Chances are it's not helping much under that context?apk addwith--upgrade.--no-cachehandlesapk update+ cleanup of cache). At the time they reference official Docker docs backing that up as a best practice (that stance later changed for several reputable sources, but they do not encourage upgrading packages either).Removing the need for
Dockerfile.gitand simplifying CI maintenanceHowever, we can easily remove the
Dockerfile.gitfor simpler maintenance by using a multi-stage build. That can default to localCOPY, or when building specifying an alternative target / ARG to get the files via git.I have little information to go by the PR that introduced the current approach beyond the PR (and this commit prior to a separate PR being raised that covers both branches / builds). I'm a bit confused with the approach. You would ideally centralize your Github Actions into a single branch to keep maintenance simple.
The
Dockerfile.gitappears to be only intended for serving this CI purpose? If so, you could just have the checkout action checkout the branch andCOPYthe files, makingDockerfile.gitredundant. You could then have a single branch that maintains a singleDockerfileonly for builds, not needing to keep it in sync across multiple branches if that appeals to you?ARG ARCHIVE_URLdoesn't appear to be relevant or used for anything? I found nothing in the PR, or several search engine queries regarding it and the URL itself appears to be a dud?gitpackage with an actual repo cloned was apparently only for benefit ofgit logto provide a commit hash to display in thetestssl.shbanner output?. But that adds not only the weight ofgitpackage, but also some extrabin/files you usually exclude from the build. You can just extract this information during the CI build and supply it as a build ARG? I understand if you want to keep it simple as-is though.The
gitpackage could also be avoided via anADDinstruction to pull in the same git content if you're not going to remove any of it viaRUN?Another option is to build the image with git URL as the build context:
NOTE: If the
.dockerignoreis important, the one in target remote git repo won't used. For the CI it wouldn't matter as you'd be checking out the repo and have a local.dockerignorefile that does apply to the remote build context. Otherwise the extrabin/files are included like withDockerfile.gitalready.