FROM alpine:3.14

# gitlab-runner-helper will try to resolve `sh` from the path. We ensure the PATH is populated by default, as some container runtimes do no longer set a default (e.g. containerd v1.2.8)
ENV PATH="${PATH:-/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin}"

# hadolint ignore=DL3018
RUN apk add --no-cache bash ca-certificates dumb-init git git-lfs miniperl \
    && ln -s miniperl /usr/bin/perl

RUN git lfs install --skip-repo

ENV BASE_PATH gitlab-runner-helper-entrypoint

COPY "$BASE_PATH/entrypoint.sh" /entrypoint
RUN chmod +x /entrypoint

COPY "$BASE_PATH/scripts" /usr/bin/
COPY --from=binary_dir gitlab-runner-helper.linux-amd64 /usr/bin/gitlab-runner-helper
RUN chmod +x /usr/bin/gitlab-runner-helper /usr/bin/gitlab-runner-build

RUN echo 'hosts: files dns' >> /etc/nsswitch.conf

ENTRYPOINT ["/usr/bin/dumb-init", "/entrypoint"]
CMD ["sh"]
