-
(RTFM welcomed) So, I have to impose consistency and discipline at work (for my sins). It seems like every Dockerfile is written a bit differently, and it is easy to write bad Dockerfiles. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
There are a few ways of going about this (sorry I took a minute to respond, the week got away from me!). I take the heart of your question to be standardizing or normalising Dockerfiles. This is. . . tricky. But depending on what exactly you're doing you can find a solution that Works Well(Tm) for your purposes :-D
So, let's say you have
So the idea is that you can now hot-swap anything in {curlies} via pypyr substitutions. Let's use Let's put the dynamic values in # ./pyproject.toml
[tool.pypyr.vars]
base_image = "python:3.10.5"
image_cmds = """set -ex; \
apt-get update; \
apt-get install -y --no-install-recommends \
autoconf \
automake"""
pip_deps = "requests pylint autopep8==1.5.7"
default_pyscript = "./your-daemon-or-script.py"
image_repo = "myrepo"
image_name = "myimagename" No real reason to use steps:
# this loads the values from the table tool.pypyr.vars in pyproject.toml into context
- pypyr.steps.configvars
- name: pypyr.steps.fileformat
comment: swap out all substitution expressions in the Dockerfile template and write to output
in:
fileFormat:
in: ops/docker/templates/my-app-dockerfile.template
out: ops/out/Dockerfile
- name: pypyr.steps.set
comment: arbitrarily set branch + build no. you prob want to get these values from the env rather than just setting here as example.
in:
set:
branch: mybranch
build_number: 1234
- name: pypyr.steps.cmd
comment: build the image specified by the newly created Dockerfile at ops/out/Dockerfile
in:
cmd: docker build -t {image_repo}/{image_name}:{branch}.{build_number} -f ./ops/out/Dockerfile . |
Beta Was this translation helpful? Give feedback.
-
steps:
# some sort of step to fetch or set the necessary variables in context here
- name: pypyr.steps.set
in:
set:
container_id: mycontainer from fedora:latest
- name: pypyr.steps.cmd
in:
cmd:
- buildah config --env GOPATH=/root/mydir {container_id}
- buildah run {container_id} /bin/sh -c 'dnf -y install --enablerepo=updates-testing make golang; mkdir -p /root/blah; make install;'
- buildah commit {container_id} buildahupstream |
Beta Was this translation helpful? Give feedback.
-
Alternatively, you could of course use pypyr to manage an integration test scenario something like this: steps:
- name: pypyr.steps.cmd
in:
cmd: docker run -d -p 8000:8000 --name test-rest-server node-docker
- name: pypyr.steps.cmd
in:
cmd: pytest tests/integration
- name: pypyr.steps.cmd
in:
cmd: docker stop test-rest-server Note: you prob want to be a bit more careful about error handling to make sure the |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
There are a few ways of going about this (sorry I took a minute to respond, the week got away from me!).
I take the heart of your question to be standardizing or normalising Dockerfiles. This is. . . tricky.
But depending on what exactly you're doing you can find a solution that Works Well(Tm) for your purposes :-D
So, let's say you have
ops/docker/templates/my-app-dockerfile.template
:So the idea is that you can now ho…