Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] try build multi stage build with tempest promtool #253

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ tcib_packages:
- qemu-img

tcib_user: tempest
tcib_builder: '{{ tempest_prometheus_image | default("quay.io/prometheus/prometheus:latest") }}'
tcib_builder_copies:
/bin/promtool: /bin/promtool
6 changes: 6 additions & 0 deletions roles/container_image_build/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ tcib_actions: []

# List of Strings, optional, <item>, Collects file from the host and stores them in the build directory.
tcib_gather_files: []

# String, Optional, 'item', Additional params to copy content from different container using buildah multi stage build, implements
tcib_builder: ''

# Dictionary, single level key:value pairs, optional, key as a source file name and value as a destination file name
tcib_builder_copies: {}
8 changes: 8 additions & 0 deletions roles/container_image_build/templates/Containerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.

{% if tcib_builder | length > 0 %}
FROM {{ tcib_builder }} as builder
{% endif %}
FROM {{ tcib_from }}
{% for key, value in tcib_args.items() %}
ARG {{ key }}={{ value | to_json }}
Expand Down Expand Up @@ -42,6 +45,11 @@ EXPOSE {{ item }}
{% for item in tcib_copies %}
COPY {{ item }}
{% endfor %}
{% if tcib_builder | length > 0 and tcib_builder_copies | length > 0 %}
{% for key, value in tcib_builder_copies.items() %}
COPY --from=builder {{ key }} {{ value }}
{% endfor %}
{% endif %}
{% if tcib_shell | length > 0 %}
SHELL {{ tcib_shell.split() | to_json }}
{% endif %}
Expand Down
9 changes: 9 additions & 0 deletions roles/container_image_build/templates/buildahfile.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ set -ev
{% for key, value in tcib_args.items() %}
export {{ key }}={{ value | to_json }}
{% endfor %}
{% if tcib_builder | length > 0 %}
BUILDER_CONTAINER=$(buildah from {{ tcib_builder }})
BUILDER_MOUNTPOINT=$(buildah mount ${BUILDER_CONTAINER})
{% endif %}
CONTAINER=$(buildah from {{ tcib_from }})
MOUNTPOINT=$(buildah mount ${CONTAINER})
{% for key, value in tcib_labels.items() %}
Expand Down Expand Up @@ -75,6 +79,11 @@ buildah add ${CONTAINER} {{ item }}
{% for item in tcib_copies %}
buildah copy ${CONTAINER} {{ item }}
{% endfor %}
{% if tcib_builder | length > 0 and tcib_builder_copies | length > 0 %}
{% for key, value in tcib_builder_copies.items() %}
buildah copy ${CONTAINER} {{ key }} {{ value }}
{% endfor %}
{% endif %}
{% for item in tcib_runs %}
{% if item is iterable and item is not string %}
buildah run ${CONTAINER} {{ item | join(' ') }}
Expand Down