Dockerfile 2.83 KB
Newer Older
Christoph Weyer's avatar
Christoph Weyer committed
1
FROM alpine:3.13.10 as builder
Christoph Weyer's avatar
Christoph Weyer committed
2 3 4 5

# ignore warning about pining version
# hadolint ignore=DL3018
RUN set -eux \
6 7 8 9 10 11 12 13 14 15 16 17
  && apk add --no-cache \
       bc \
       cargo \
       gcc \
       libffi-dev \
       musl-dev \
       openssl-dev \
       py3-pip \
       py3-wheel \
       python3 \
       python3-dev \
       rust
Christoph Weyer's avatar
Christoph Weyer committed
18 19 20 21 22

COPY requirements.txt /

# hadolint ignore=DL4006
RUN set -eux \
23 24 25 26 27 28
  && pip3 install \
         --no-cache-dir --no-warn-script-location -r /requirements.txt \
  && ansible-lint --version | head -1 | grep -E 'ansible-lint[[:space:]]+[0-9]+' \
  && rm -f /requirements.txt \
  && find /usr/lib/ -name '__pycache__' -print0 | xargs -0 -n1 rm -rf \
  && find /usr/lib/ -name '*.pyc' -print0 | xargs -0 -n1 rm -rf
Christoph Weyer's avatar
Christoph Weyer committed
29

Christoph Weyer's avatar
Christoph Weyer committed
30

Christoph Weyer's avatar
Christoph Weyer committed
31
# hadolint ignore=DL3059
Christoph Weyer's avatar
Christoph Weyer committed
32
# RUN mkdir -p /kaniko/0/usr/lib/python3.8/
Christoph Weyer's avatar
Christoph Weyer committed
33
# hadolint ignore=DL3059
Christoph Weyer's avatar
Christoph Weyer committed
34
# RUN cp -r /usr/lib/python3.8/site-packages /kaniko/0/usr/lib/python3.8/
Christoph Weyer's avatar
Christoph Weyer committed
35

Christoph Weyer's avatar
Christoph Weyer committed
36
FROM alpine:3.13.10 as production
Christoph Weyer's avatar
Christoph Weyer committed
37

38 39 40 41 42 43
# define ARG variable after FROM
ARG DOCKER_USER="nonroot"
ARG DOCKER_HOME="/home/$DOCKER_USER"
ARG DOCKER_WORKDIR="/work"
ARG ENTRYPOINT="ansible-lint"

Christoph Weyer's avatar
Christoph Weyer committed
44 45 46 47 48
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
LABEL org.opencontainers.image.title="tuhh/e-17/weyer/ansiblelint"
LABEL org.opencontainers.image.source="https://collaborating.tuhh.de/e-17/staff/weyer/gitlab/ci-cd/ci-ansible-lint"
#LABEL org.opencontainers.image.version=""
#LABEL org.opencontainers.image.commit=""
49
LABEL org.opencontainers.image.description="Ansible Lint - A Docker image for GitLab CI"
Christoph Weyer's avatar
Christoph Weyer committed
50 51
LABEL org.opencontainers.image.authors="Christoph Weyer <c.weyer@tuhh.de>"

52 53 54 55
RUN set -eux && \
    addgroup "$DOCKER_USER" && \
    adduser "$DOCKER_USER" -G "$DOCKER_USER" -h "$DOCKER_HOME" -D

Christoph Weyer's avatar
Christoph Weyer committed
56 57
# ignore warning about pining version
# hadolint ignore=DL3018,DL4006
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
RUN set -eux && \
    apk add --no-cache \
            bash \
            git \
            python3 \
    && \
    ln -sf ansible /usr/bin/ansible-config && \
    ln -sf ansible /usr/bin/ansible-console && \
    ln -sf ansible /usr/bin/ansible-doc && \
    ln -sf ansible /usr/bin/ansible-galaxy && \
    ln -sf ansible /usr/bin/ansible-inventory && \
    ln -sf ansible /usr/bin/ansible-playbook && \
    ln -sf ansible /usr/bin/ansible-pull && \
    ln -sf ansible /usr/bin/ansible-test && \
    ln -sf ansible /usr/bin/ansible-vault && \
    find /usr/lib/ -name '__pycache__' -print0 | xargs -0 -n1 rm -rf && \
    find /usr/lib/ -name '*.pyc' -print0 | xargs -0 -n1 rm -rf
Christoph Weyer's avatar
Christoph Weyer committed
75

Christoph Weyer's avatar
Christoph Weyer committed
76
COPY --from=builder /usr/lib/python3.8/site-packages/ /usr/lib/python3.8/site-packages/
Christoph Weyer's avatar
Christoph Weyer committed
77 78 79 80
COPY --from=builder /usr/bin/ansible-lint /usr/bin/ansible-lint
COPY --from=builder /usr/bin/ansible /usr/bin/ansible
COPY --from=builder /usr/bin/ansible-connection /usr/bin/ansible-connection

81 82 83 84 85 86 87
USER ${DOCKER_USER}

ENV ENTRYPOINT="${ENTRYPOINT}"

COPY entrypoint.sh /

WORKDIR ${DOCKER_WORKDIR}
Christoph Weyer's avatar
Christoph Weyer committed
88

89
ENTRYPOINT ["/entrypoint.sh"]
Christoph Weyer's avatar
Christoph Weyer committed
90
CMD ["--version"]