Skip to content

Commit 4e82908

Browse files
asmacdofabianvf
andauthored
Allow publishing of Ansible 2.9 and 2.11 images (#5311)
* Allow publishing of Ansible 2.9 and 2.11 images Related to #5115 This PR introduces the Dockerfile and infrastructure to build Ansible 2.9 and Ansible 2.11 images side by side. This commit does not integrate these changes into CI, and therefore will need to be mered alongside a follow-up PR to intetgrate with GitHub actions. Co-authored-by: Austin Macdonald <[email protected]> Co-authored-by: Fabian von Feilitzsch <[email protected]> Signed-off-by: austin <[email protected]> * use new preview dependency image to create preview base * build and push ansible tags * e2e ansible molecule should build 2.9 images * simplify make * fixup: fix makefile imagebuild dep * fixup: more tweaks * fixup: action to use 2.11 dir * first draft deploy-manual * finish full separation of 2.9 and 2.11 dirs * fixup: s/secret/github/ * fixup: cleanup Signed-off-by: austin <[email protected]> Co-authored-by: Fabian von Feilitzsch <[email protected]>
1 parent e975298 commit 4e82908

File tree

8 files changed

+711
-13
lines changed

8 files changed

+711
-13
lines changed

.github/workflows/deploy-manual.yml

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
ansible_operator_base_tag:
77
description: ansible-operator-base image tag, ex. "6e1b47e6ca7c507b8ecf197a8edcd412dd64d85d"
88
required: false
9+
ansible_operator_211_base_tag:
10+
description: ansible-operator-2.11-preview-base image tag, ex. "6e1b47e6ca7c507b8ecf197a8edcd412dd64d85d"
11+
required: false
912

1013
jobs:
1114
# Build the ansible-operator-base image.
@@ -32,8 +35,9 @@ jobs:
3235
with:
3336
fetch-depth: 1
3437

35-
- name: create tag
36-
id: tag
38+
# Copied this for 2.11 rather than use a matrix because eventually 2.11 will be default and this will be removed.
39+
- name: create 2.9-base tag
40+
id: 29_base_tag
3741
run: |
3842
set -e
3943
IMG=quay.io/${{ github.repository_owner }}/ansible-operator-base
@@ -45,36 +49,82 @@ jobs:
4549
echo ::set-output name=tag::${IMG}:${TAG}
4650
echo ::set-output name=git_commit::${GIT_COMMIT}
4751
48-
- name: build and push
52+
- name: create 2.11-base tag
53+
id: 211_base_tag
54+
run: |
55+
set -e
56+
IMG=quay.io/${{ github.repository_owner }}/ansible-operator-2.11-preview-base
57+
TAG="${{ github.event.inputs.ansible_operator_211_base_tag }}"
58+
if [[ "$TAG" == "" ]]; then
59+
TAG="$(git branch --show-current)-${GIT_COMMIT}"
60+
fi
61+
echo ::set-output name=tag::${IMG}:${TAG}
62+
echo ::set-output name=git_commit::${GIT_COMMIT}
63+
64+
- name: build and push ansible 2.9 dep image
4965
uses: docker/build-push-action@v2
5066
with:
5167
file: ./images/ansible-operator/base.Dockerfile
5268
context: ./images/ansible-operator
5369
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
5470
push: true
55-
tags: ${{ steps.tag.outputs.tag }}
71+
tags: ${{ steps.tag.outputs.29_base_tag }}
72+
build-args: |
73+
GIT_COMMIT=${{ steps.tag.outputs.git_commit }}
74+
75+
- name: build and push ansible 2.11 dep image
76+
uses: docker/build-push-action@v2
77+
with:
78+
file: ./images/ansible-operator-2.11-preview/base.Dockerfile
79+
context: ./images/ansible-operator
80+
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
81+
push: true
82+
tags: ${{ steps.tag.outputs.211_base_tag }}
5683
build-args: |
5784
GIT_COMMIT=${{ steps.tag.outputs.git_commit }}
5885
5986
# This change will be staged and committed in the PR pushed below.
6087
# The script below will fail if no change was made.
61-
- name: update ansible-operator base
88+
- name: update base of ansible-operator 2.9
6289
id: update
6390
run: |
6491
set -ex
65-
sed -i -E 's|FROM quay\.io/operator-framework/ansible-operator-base:.+|FROM ${{ steps.tag.outputs.tag }}|g' images/ansible-operator/Dockerfile
92+
sed -i -E 's|FROM quay\.io/operator-framework/ansible-operator-base:.+|FROM ${{ steps.tag.outputs.29_base_tag }}|g' images/ansible-operator/Dockerfile
6693
git diff --exit-code --quiet && echo "Failed to update images/ansible-operator/Dockerfile" && exit 1
6794
REF="${{ github.event.ref }}"
6895
echo ::set-output name=branch_name::"${REF##*/}"
6996
70-
- name: create PR
97+
- name: create PR for ansible-operator 2.9 Dockerfile
7198
uses: peter-evans/create-pull-request@v3
7299
with:
73-
title: "[${{ steps.update.outputs.branch_name }}] image(ansible-operator): bump base to ${{ steps.tag.outputs.tag }}"
100+
title: "[${{ steps.update.outputs.branch_name }}] image(ansible-operator): bump base to ${{ steps.tag.outputs.29_base_tag }}"
74101
commit-message: |
75-
[${{ steps.update.outputs.branch_name }}] image(ansible-operator): bump base to ${{ steps.tag.outputs.tag }}
102+
[${{ steps.update.outputs.branch_name }}] image(ansible-operator): bump base to ${{ steps.tag.outputs.29_base_tag }}
76103
77104
Signed-off-by: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
78105
body: "New ansible-operator-base image built by https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
79106
delete-branch: true
80107
branch-suffix: short-commit-hash
108+
109+
# This change will be staged and committed in the PR pushed below.
110+
# The script below will fail if no change was made.
111+
- name: update base of ansible-operator-2.11-preview
112+
id: update
113+
run: |
114+
set -ex
115+
sed -i -E 's|FROM quay\.io/operator-framework/ansible-operator-2.11-preview-base:.+|FROM ${{ steps.tag.outputs.211_base_tag }}|g' images/ansible-operator/Dockerfile
116+
git diff --exit-code --quiet && echo "Failed to update images/ansible-operator-11-preview-base/Dockerfile" && exit 1
117+
REF="${{ github.event.ref }}"
118+
echo ::set-output name=branch_name::"${REF##*/}"
119+
120+
- name: create PR for ansible-operator-2.11-preview Dockerfile
121+
uses: peter-evans/create-pull-request@v3
122+
with:
123+
title: "[${{ steps.update.outputs.branch_name }}] image(ansible-operator-2.11-preview): bump base to ${{ steps.tag.outputs.211_base_tag }}"
124+
commit-message: |
125+
[${{ steps.update.outputs.branch_name }}] image(ansible-operator-2.11-preview): bump base to ${{ steps.tag.outputs.211_base_tag }}
126+
127+
Signed-off-by: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
128+
body: "New ansible-operator-2.11-preview-base image built by https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
129+
delete-branch: true
130+
branch-suffix: short-commit-hash

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
environment: deploy
7373
strategy:
7474
matrix:
75-
id: ["operator-sdk", "ansible-operator", "helm-operator", "scorecard-test"]
75+
id: ["operator-sdk", "helm-operator", "scorecard-test", "ansible-operator", "ansible-operator-2.11-preview"]
7676
steps:
7777

7878
- name: set up qemu

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,14 @@ build/scorecard-test build/scorecard-test-kuttl build/custom-scorecard-tests:
8282

8383
# Convenience wrapper for building all remotely hosted images.
8484
.PHONY: image-build
85-
IMAGE_TARGET_LIST = operator-sdk helm-operator ansible-operator scorecard-test scorecard-test-kuttl
85+
IMAGE_TARGET_LIST = operator-sdk helm-operator ansible-operator ansible-operator-2.11-preview scorecard-test scorecard-test-kuttl
8686
image-build: $(foreach i,$(IMAGE_TARGET_LIST),image/$(i)) ## Build all images.
8787

88+
# Convenience wrapper for building dependency base images.
89+
.PHONY: image-build-base
90+
IMAGE_BASE_TARGET_LIST = ansible-operator ansible-operator-2.11-preview
91+
image-build-base: $(foreach i,$(IMAGE_BASE_TARGET_LIST),image-base/$(i)) ## Build all images.
92+
8893
# Build an image.
8994
BUILD_IMAGE_REPO = quay.io/operator-framework
9095
# When running in a terminal, this will be false. If true (ex. CI), print plain progress.
@@ -95,6 +100,9 @@ image/%: export DOCKER_CLI_EXPERIMENTAL = enabled
95100
image/%:
96101
docker buildx build $(DOCKER_PROGRESS) -t $(BUILD_IMAGE_REPO)/$*:dev -f ./images/$*/Dockerfile --load .
97102

103+
image-base/%: export DOCKER_CLI_EXPERIMENTAL = enabled
104+
image-base/%:
105+
docker buildx build $(DOCKER_PROGRESS) -t $(BUILD_IMAGE_REPO)/$*:dev -f ./images/$*/base.Dockerfile --load .
98106
##@ Release
99107

100108
.PHONY: release
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Build the manager binary
2+
FROM --platform=$BUILDPLATFORM golang:1.16 as builder
3+
ARG TARGETARCH
4+
5+
WORKDIR /workspace
6+
# Copy the Go Modules manifests
7+
COPY go.mod go.mod
8+
COPY go.sum go.sum
9+
# cache deps before building and copying source so that we don't need to re-download as much
10+
# and so that source changes don't invalidate our downloaded layer
11+
RUN go mod download
12+
13+
# Copy the go source
14+
COPY . .
15+
16+
# Build
17+
RUN GOOS=linux GOARCH=$TARGETARCH make build/ansible-operator
18+
19+
# Final image.
20+
# TODO(asmacdo) update GH action to set this
21+
FROM quay.io/operator-framework/ansible-operator-2.11-preview-base:dev
22+
23+
ENV HOME=/opt/ansible \
24+
USER_NAME=ansible \
25+
USER_UID=1001
26+
27+
# Ensure directory permissions are properly set
28+
RUN echo "${USER_NAME}:x:${USER_UID}:0:${USER_NAME} user:${HOME}:/sbin/nologin" >> /etc/passwd \
29+
&& mkdir -p ${HOME}/.ansible/tmp \
30+
&& chown -R ${USER_UID}:0 ${HOME} \
31+
&& chmod -R ug+rwx ${HOME}
32+
33+
WORKDIR ${HOME}
34+
USER ${USER_UID}
35+
36+
COPY --from=builder /workspace/build/ansible-operator /usr/local/bin/ansible-operator
37+
38+
ENTRYPOINT ["/tini", "--", "/usr/local/bin/ansible-operator", "run", "--watches-file=./watches.yaml"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
ansible-runner = "~=1.4.7"
8+
ansible-runner-http = "==1.0.0"
9+
ipaddress = "==1.0.23"
10+
openshift = "~=0.12.0"
11+
jmespath = "==0.10.0"
12+
# cryptography needs to be pinned to 3.3.2 as this is the last version
13+
# before its setup requires rust, which is not available via RPM in the
14+
# base image. This pin should be re-evaluated once the base image is updated.
15+
cryptography = "==3.3.2"
16+
ansible-core = "~=2.11.0"
17+
18+
[dev-packages]
19+
20+
[requires]
21+
python_version = "3.8"

0 commit comments

Comments
 (0)