# create base image for cleanbuild
-FROM registry.gitlab.com/pld-linux/pld
+FROM registry.gitlab.com/pld-linux/pld AS base
+FROM base AS dist
+WORKDIR /dist
+
+COPY rpmmacros ./home/builder/.rpmmacros
+# overwrite with our config (it defines same path, but disabled)
+COPY localrpms.conf ./etc/poldek/source.conf
+
+# use sane permissions until solved upstream
+# https://gitlab.com/gitlab-org/gitlab-runner/issues/1736
+RUN chmod -R a+rX,og-w .
+
+FROM base
RUN set -x \
# first upgrade to latest
&& poldek --upgrade-dist \
&& poldek-config keep_downloads yes \
&& poldek --clean-whole
-# overwrite with our config (it defines same path, but disabled)
-COPY localrpms.conf /etc/poldek/source.conf
+COPY --from=dist /dist /
# switch user
USER builder
-
-WORKDIR /home/services/builder
-
-COPY rpmmacros .rpmmacros
+WORKDIR /home/builder
# Use sleep to run forever
CMD ["sleep", "infinity"]