FROM alpine
MAINTAINER Disassembler <disassembler@dasm.cz>

RUN \
 # Install runtime dependencies
 apk --no-cache add nodejs nginx

RUN \
 # Install build dependencies
 apk --no-cache add --virtual .deps git yarn
 # Clone CrisisCleanup
 && git clone --depth 1 https://github.com/CrisisCleanup/crisiscleanup-web /srv/crisiscleanup \
 # Install NodeJS dependencies
 && cd /srv/crisiscleanup \
 && yarn install \
 # Generate static resources
 && APP_ENV=prod yarn run build \
 # Create OS user
 && addgroup -S -g 8005 cc \
 && adduser -S -u 8005 -h /srv/crisiscleanup -s /bin/false -g cc -G cc cc \
 && chown -R cc:cc /srv/crisiscleanup \
 # Cleanup
 && apk --no-cache del .deps \
 && find /srv/crisiscleanup -name '.git*' -exec rm -rf {} + \
 && rm -rf /usr/local/share/.cache

VOLUME ["/srv/crisiscleanup/config"]
EXPOSE 8080

WORKDIR /srv/crisiscleanup
CMD ["s6-svscan", "/etc/services.d"]
