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

Include migration builds in image builds #716

Merged
merged 2 commits into from
Feb 14, 2020
Merged
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
45 changes: 36 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,17 @@ RUN --mount=source=.cargo,target=/home/builder/.cargo \
FROM scratch AS package
COPY --from=rpmbuild /home/builder/rpmbuild/RPMS/*/*.rpm /output/

FROM sdk AS imgbuild
FROM sdk AS repobuild
ARG PACKAGES
ARG ARCH
ARG VERSION_ID
ARG BUILD_ID
ARG NOCACHE
ARG VARIANT
ENV VARIANT=${VARIANT} VERSION_ID=${VERSION_ID} BUILD_ID=${BUILD_ID}
WORKDIR /root

zmrow marked this conversation as resolved.
Show resolved Hide resolved
USER root
RUN --mount=target=/host \
mkdir -p /local/rpms ./rpmbuild/RPMS \
mkdir -p /local/rpms /local/migrations ./rpmbuild/RPMS \
&& ln -s /host/build/*.rpm ./rpmbuild/RPMS \
&& cp /host/build/thar-${ARCH}-migrations-*.rpm /local/migrations \
&& createrepo_c \
-o ./rpmbuild/RPMS \
-x '*-debuginfo-*.rpm' \
Expand All @@ -114,10 +111,40 @@ RUN --mount=target=/host \
install $(printf "thar-${ARCH}-%s\n" ${PACKAGES}) \
&& mv *.rpm /local/rpms \
&& createrepo_c /local/rpms \
&& /host/tools/rpm2img \
--package-dir=/local/rpms \
--output-dir=/local/output \
&& echo ${NOCACHE}

FROM repobuild as imgbuild
ARG ARCH
ARG VERSION_ID
ARG BUILD_ID
ARG NOCACHE
ARG VARIANT
ENV VARIANT=${VARIANT} VERSION_ID=${VERSION_ID} BUILD_ID=${BUILD_ID}
WORKDIR /root

USER root
RUN --mount=target=/host \
/host/tools/rpm2img \
--package-dir=/local/rpms \
--output-dir=/local/output \
&& echo ${NOCACHE}

FROM repobuild as migrationbuild
ARG ARCH
ARG VERSION_ID
ARG BUILD_ID
ARG NOCACHE
ARG VARIANT
ENV VARIANT=${VARIANT} VERSION_ID=${VERSION_ID} BUILD_ID=${BUILD_ID}
WORKDIR /root

USER root
RUN --mount=target=/host \
/host/tools/rpm2migrations \
--package-dir=/local/migrations \
--output-dir=/local/output \
&& echo ${NOCACHE}

FROM scratch AS variant
COPY --from=imgbuild /local/output/* /output/
COPY --from=migrationbuild /local/output/* /output/
27 changes: 27 additions & 0 deletions packages/workspaces/workspaces.spec
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ Summary: Thar pre-init system setup
%description -n %{_cross_os}preinit
%{summary}.

%package -n %{_cross_os}migrations
Summary: Thar data store migrations
%description -n %{_cross_os}migrations
%{summary}.

%prep
%setup -T -c
%cargo_prep
Expand Down Expand Up @@ -169,6 +174,11 @@ mkdir bin
-p apiclient \
%{nil}

# Build the migrations
for crate in $(find %{_builddir}/workspaces/api/migration/migrations -name 'Cargo.toml'); do
%cargo_build_static --manifest-path "${crate}"
done

%install
install -d %{buildroot}%{_cross_bindir}
for p in \
Expand All @@ -191,6 +201,19 @@ for p in growpart preinit ; do
install -p -m 0755 ${HOME}/.cache/%{__cargo_target}/release/${p} %{buildroot}%{_cross_sbindir}
done

install -d %{buildroot}%{_cross_datadir}/migrations
zmrow marked this conversation as resolved.
Show resolved Hide resolved
for version_path in %{_builddir}/workspaces/api/migration/migrations/*; do
for migration_path in "${version_path}"/*; do
Comment on lines +205 to +206
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should be consistent about quoting. (I don't like quoting paths containing globs, but if shellcheck complains, it's fine.)

version="${version_path##*/}"
crate_name="${migration_path##*/}"
migration_binary_name="migrate_${version}_${crate_name#migrate-}"
built_path="${HOME}/.cache/%{__cargo_target_static}/release/${crate_name}"
target_path="%{buildroot}%{_cross_datadir}/migrations/${migration_binary_name}"

install -m 0555 "${built_path}" "${target_path}"
done
done

install -d %{buildroot}%{migration_dir}

install -d %{buildroot}%{_cross_datadir}/thar
Expand Down Expand Up @@ -271,6 +294,10 @@ install -p -m 0644 %{S:201} %{buildroot}%{_cross_tmpfilesdir}/host-containers.co
%{migration_dir}
%{_cross_tmpfilesdir}/migration.conf

%files -n %{_cross_os}migrations
%dir %{_cross_datadir}/migrations
%{_cross_datadir}/migrations
zmrow marked this conversation as resolved.
Show resolved Hide resolved

%files -n %{_cross_os}settings-committer
%{_cross_bindir}/settings-committer

Expand Down
46 changes: 46 additions & 0 deletions tools/rpm2migrations
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
#
# Retrieve migrations from the RPM and output an appropriately named tarball
set -eu -o pipefail
shopt -qs failglob

for opt in "$@"; do
optarg="$(expr "${opt}" : '[^=]*=\(.*\)')"
case "${opt}" in
--package-dir=*) PACKAGE_DIR="${optarg}" ;;
--output-dir=*) OUTPUT_DIR="${optarg}" ;;
esac
done

mkdir -p "${OUTPUT_DIR}"

MIGRATIONS_ARCHIVE="thar-${ARCH}-${VARIANT}-${VERSION_ID}-${BUILD_ID}-migrations.tar"
ROOT_TEMP="$(mktemp -d)"
SYS_ROOT="${ARCH}-thar-linux-gnu/sys-root"
MIGRATIONS_DIR="${ROOT_TEMP}/${SYS_ROOT}/usr/share/migrations"

# "Install" the migrations (just puts them in $MIGRATIONS_DIR)
rpm -iv --root "${ROOT_TEMP}" "${PACKAGE_DIR}"/*.rpm
zmrow marked this conversation as resolved.
Show resolved Hide resolved

if [ ! -d "${MIGRATIONS_DIR}" ]; then
echo "Migrations directory does not exist: ${MIGRATIONS_DIR}"
rm -rf "${ROOT_TEMP}"
exit 1
fi

# lz4 compress each migration
for migration in "${MIGRATIONS_DIR}"/*; do
lz4 -v "${migration}" "${migration}.lz4"
done

# Tar up migrations with a .lz4 extension if they exist.
# Otherwise create an empty archive
pushd "${MIGRATIONS_DIR}"
if ls *.lz4 &> /dev/null; then
jahkeup marked this conversation as resolved.
Show resolved Hide resolved
tar -cvf "${OUTPUT_DIR}/${MIGRATIONS_ARCHIVE}" *.lz4
else
tar -cvf "${OUTPUT_DIR}/${MIGRATIONS_ARCHIVE}" --files-from /dev/null
fi
popd

rm -rf "${ROOT_TEMP}"

This file was deleted.

40 changes: 0 additions & 40 deletions workspaces/api/migration/migrations/v1.1/testmigration/src/main.rs

This file was deleted.