FROM golang:1.11.4 as envtpl

ARG HTTP_PROXY=
ARG HTTPS_PROXY=
ARG http_proxy=
ARG https_proxy=

RUN apt-get update -y && apt-get install -y git

RUN git clone https://github.com/subfuzion/envtpl /src \
  && cd /src \
  && git checkout v1.0.0 \
  && CGO_ENABLED=0 GOOS=linux go build \
    -ldflags "-X main.AppVersionMetadata=$(date -u +%s)" \
    -a -installsuffix cgo -o ./bin/envtpl ./cmd/envtpl/.

FROM alpine:3.9

ARG HTTP_PROXY=
ARG HTTPS_PROXY=
ARG http_proxy=
ARG https_proxy=

COPY --from=envtpl /src/bin/envtpl /usr/local/bin/envtpl

RUN apk --no-cache add \
    build-base \
    git \
    libffi-dev \
    libxslt-dev \
    linux-headers \
    openssl-dev \
    py-pillow \
    py-pip \
    py-setuptools \
    python \
    python-dev \
    sqlite-dev \
    yaml-dev \
    sudo \
    nodejs \
    npm

RUN adduser -D w3af

RUN git clone --depth=1 \
        --branch=master \
        https://github.com/andresriancho/w3af.git /home/w3af/w3af \
  && rm -rf /home/w3af/w3af/.git \
  && chown -R w3af /home/w3af/w3af

RUN cd /home/w3af/w3af \
  && ( ./w3af_console || . /tmp/w3af_dependency_install.sh )

COPY run-audit.sh /usr/local/bin/run-audit
RUN chmod +x /usr/local/bin/run-audit

USER w3af
WORKDIR /home/w3af/w3af

COPY audit.w3af.tmpl /home/w3af/w3af/audit.w3af.tmpl

ENV HTTP_PROXY=
ENV HTTPS_PROXY=
ENV http_proxy=
ENV https_proxy=

CMD ["./w3af_console"]