-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathMakefile
More file actions
177 lines (169 loc) · 7.49 KB
/
Makefile
File metadata and controls
177 lines (169 loc) · 7.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Default value for BASE_IMAGE
BASE_IMAGE ?= registry.access.redhat.com/ubi9/ubi-minimal:latest
# Default value for CONTAINERFILE
CONTAINERFILE ?= Dockerfile
# Define the AWK command based on platform (gawk on macOS, awk elsewhere)
AWK = awk
ifeq ($(shell uname),Darwin)
AWK = gawk
endif
PYTHON = python3.12
# Generate the ubi.repo file from the specified BASE_IMAGE
# Usage: make generate-repo-file [BASE_IMAGE=<image>]
# Example: make generate-repo-file BASE_IMAGE=registry.access.redhat.com/ubi9/ubi:latest
# make generate-repo-file (uses default BASE_IMAGE)
.PHONY: generate-repo-file
generate-repo-file:
podman run -it $(BASE_IMAGE) cat /etc/yum.repos.d/ubi.repo > ubi.repo
sed -i 's/ubi-9-appstream-source-rpms/ubi-9-for-x86_64-appstream-source-rpms/' ubi.repo
sed -i 's/ubi-9-appstream-rpms/ubi-9-for-x86_64-appstream-rpms/' ubi.repo
sed -i 's/ubi-9-baseos-source-rpms/ubi-9-for-x86_64-baseos-source-rpms/' ubi.repo
sed -i 's/ubi-9-baseos-rpms/ubi-9-for-x86_64-baseos-rpms/' ubi.repo
sed -i 's/\r$$//' ubi.repo
sed -i '/\[.*x86_64.*\]/,/^\[/ s/enabled[[:space:]]*=[[:space:]]*0/enabled = 1/g' ubi.repo
# Generate rpms.in.yaml listing RPM packages installed via yum, dnf, or microdnf from CONTAINERFILE
# Usage: make generate-rpms-in-yaml [CONTAINERFILE=<path>]
# Example: make generate-rpms-in-yaml CONTAINERFILE=Containerfile
# make generate-rpms-in-yaml (uses default CONTAINERFILE=Dockerfile)
.PHONY: generate-rpms-in-yaml
generate-rpms-in-yaml:
@if [ ! -f "$(CONTAINERFILE)" ]; then \
exit 1; \
fi
@if ! command -v $(PYTHON) >/dev/null 2>&1; then \
exit 2; \
fi;
@${PYTHON} -m venv /tmp/make_venv_script && \
source /tmp/make_venv_script/bin/activate && \
pip3 install dockerfile-parse && \
${PYTHON} .hermetic_builds/parse_dockerfile.py && \
deactivate && \
rm -rf /tmp/make_venv_script
# Generate rpms.lock.yaml using rpm-lockfile-prototype
# Usage: make generate-rpm-lockfile [BASE_IMAGE=<image>]
# Example: make generate-rpm-lockfile BASE_IMAGE=registry.access.redhat.com/ubi9/ubi:latest
# make generate-rpm-lockfile (uses default BASE_IMAGE)
.PHONY: generate-rpm-lockfile
generate-rpm-lockfile: rpms.in.yaml
@curl -s https://raw.githubusercontent.com/konflux-ci/rpm-lockfile-prototype/refs/heads/main/Containerfile | \
podman build -t localhost/rpm-lockfile-prototype -
@container_dir=/work; \
podman run --rm -v $${PWD}:$${container_dir} localhost/rpm-lockfile-prototype:latest --outfile=$${container_dir}/rpms.lock.yaml --image $(BASE_IMAGE) $${container_dir}/rpms.in.yaml
@if [ ! -f rpms.lock.yaml ]; then \
echo "Error: rpms.lock.yaml was not generated"; \
exit 1; \
fi
# Generate rpms.lock.yaml using rpm-lockfile-prototype with enable subscription
# TODO:
# https://konflux.pages.redhat.com/docs/users/building/activation-keys-subscription.html
# export KEY_NAME=<subscription key>
# export ORG_ID=<org id>
# podman run --rm -it -e KEY_NAME=${KEY_NAME} -e ORG_ID=${ORG_ID} -v $(pwd):/source:Z registry.access.redhat.com/ubi9
# subscription-manager register --activationkey="$KEY_NAME" --org="$ORG_ID"
# subscription-manager refresh
# cp -r /etc/pki/entitlement /source
# cp /etc/rhsm/ca/redhat-uep.pem /source
# cp /etc/yum.repos.d/redhat.repo /source/redhat.repo
# exit
# sed -i "s/$(uname -m)/\$basearch/g" redhat.repo
# update rpms.in.yaml (add redhat.repo to repofiles)
#
# Usage: make generate-rpm-lockfile [BASE_IMAGE=<image>]
# Example: make generate-rpm-lockfile BASE_IMAGE=registry.access.redhat.com/ubi9/ubi:latest
# make generate-rpm-lockfile (uses default BASE_IMAGE)
#
.PHONY: generate-rpm-lockfile-subscription
generate-rpm-lockfile-subscription: rpms.in.yaml
@curl -s https://raw.githubusercontent.com/konflux-ci/rpm-lockfile-prototype/refs/heads/main/Containerfile | \
podman build -t localhost/rpm-lockfile-prototype -
@container_dir=/work; \
podman run --rm -v $${PWD}:$${container_dir} -v $${PWD}/entitlement/:/etc/pki/entitlement -v $${PWD}/redhat-uep.pem:/etc/rhsm/ca/redhat-uep.pem localhost/rpm-lockfile-prototype:latest --outfile=$${container_dir}/rpms.lock.yaml --image $(BASE_IMAGE) $${container_dir}/rpms.in.yaml
@if [ ! -f rpms.lock.yaml ]; then \
echo "Error: rpms.lock.yaml was not generated"; \
exit 1; \
fi
# Generate requirements.txt from Poetry or Pipenv lock files
# Usage: make generate-requirements-txt
# Example: make generate-requirements-txt
.PHONY: generate-requirements-txt
generate-requirements-txt:
${PYTHON} -m venv /tmp/make_venv_script && \
source /tmp/make_venv_script/bin/activate && \
pip3 install poetry poetry-plugin-export pipenv
@if [ -f poetry.lock ]; then \
source /tmp/make_venv_script/bin/activate && poetry lock && poetry export --format requirements.txt --output requirements.txt; \
elif [ -f Pipfile.lock ]; then \
pipenv requirements > requirements.txt; \
elif [ -f requirements.txt ]; then \
exit 0; \
else \
echo "Error: Unable to generate requirements.txt file"; \
exit 1; \
fi
@if [ ! -f requirements.txt ]; then \
echo "Error: requirements.txt was not generated"; \
exit 1; \
fi
@rm -rf /tmp/make_venv_script
# Generate requirements-build.in from [build-system] in pyproject.toml
# Usage: make generate-requirements-build-in
# Example: make generate-requirements-build-in
.PHONY: generate-requirements-build-in
generate-requirements-build-in:
@> requirements-build.in
@if [ ! -f pyproject.toml ]; then \
echo "Error: pyproject.toml not found"; \
exit 1; \
fi
@if ! grep -q '^\[build-system\]' pyproject.toml; then \
exit 0; \
fi
@requires=$$(sed -n '/^\[build-system\]/,/^\[/p' pyproject.toml | \
grep 'requires[[:space:]]*=' | \
sed 's/.*requires[[:space:]]*=[[:space:]]*\[\(.*\)\]/\1/' | \
sed 's/"//g; s/,[[:space:]]*/\n/g' | \
sed 's/^[[:space:]]*//; s/[[:space:]]*$$//; /^$$/d'); \
if [ -z "$$requires" ]; then \
exit 0; \
fi; \
> requirements-build.in; \
for pkg in $$requires; do \
if echo "$$pkg" | grep -q "=="; then \
echo "$$pkg" >> requirements-build.in; \
else \
version=$$(curl -s "https://pypi.org/pypi/$$pkg/json" | \
sed -n 's/.*"version":[[:space:]]*"\([^"]*\)".*/\1/p' | head -1); \
if [ -z "$$version" ]; then \
echo "Error: Failed to fetch version for $$pkg from PyPI"; \
exit 1; \
fi; \
echo "$$pkg==$$version" >> requirements-build.in; \
fi; \
done
@if [ ! -f .hermetic_builds/add_manual_build_dependencies.sh ] || [ ! -f .hermetic_builds/add_manual_build_dependencies.sh ]; then \
echo "Error: Missing scripts in .hermetic_builds directory"; \
exit 1; \
fi
.hermetic_builds/add_manual_build_dependencies.sh
@if [ ! -f requirements-build.in ]; then \
echo "Error: requirements-build.in was not generated"; \
exit 1; \
fi
# Generate requirements-build.txt using pip-tools and pybuild-deps
# Usage: make generate-requirements-build-txt [BASE_IMAGE=<image>]
# Example: make generate-requirements-build-txt BASE_IMAGE=registry.access.redhat.com/ubi9/ubi:latest
.PHONY: generate-requirements-build-txt
generate-requirements-build-txt:
@if [ ! -f requirements.txt ]; then \
echo "Error: requirements.txt not found"; \
exit 1; \
fi
@if [ ! -f .hermetic_builds/prep_python_build_container_dependencies.sh ] || [ ! -f .hermetic_builds/generate_requirements_build.sh ]; then \
echo "Error: Missing scripts in .hermetic_builds directory"; \
exit 1; \
fi
@podman run -it -v "$$(pwd)":/var/tmp:rw --user 0:0 $(BASE_IMAGE) bash -c "/var/tmp/.hermetic_builds/prep_python_build_container_dependencies.sh && /var/tmp/.hermetic_builds/generate_requirements_build.sh"
@if [ ! -f requirements-build.txt ]; then \
echo "Error: requirements-build.txt was not generated"; \
exit 1; \
fi