# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes. # Copyright (C) 2022 Dominic Grimm # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . FROM docker.io/crystallang/crystal:1.7.2-alpine as crystal FROM tdewolff/minify:latest as minify FROM crystal as micrate-deps WORKDIR /usr/src/micrate COPY ./micrate/shard.yml ./micrate/shard.lock ./ RUN shards install --production FROM crystal as micrate-builder WORKDIR /usr/src/micrate COPY --from=micrate-deps /usr/src/micrate/shard.yml /usr/src/micrate/shard.lock ./ COPY --from=micrate-deps /usr/src/micrate/lib ./lib COPY ./micrate/src ./src RUN shards build --release --static --verbose -s -p -t FROM minify as public WORKDIR /usr/src/public COPY ./public ./src RUN minify -r -o ./dist ./src FROM crystal as deps WORKDIR /usr/src/mentorenwahl COPY ./shard.yml ./shard.lock ./ RUN shards install --production FROM minify as templates-html WORKDIR /usr/src/templates/html COPY ./templates/html . RUN find . -name "*.html.ecr" -type f | xargs -I % sh -c 'mv "%" "$(basename -s .html.ecr "%").min.html"' RUN minify . -r -o . RUN find . -name "*.min.html" -type f | xargs -I % sh -c 'mv "%" "%.ecr"' FROM crystal as builder WORKDIR /usr/src/mentorenwahl RUN apk add --no-cache pcre2-dev RUN mkdir deps COPY --from=deps /usr/src/mentorenwahl/shard.yml /usr/src/mentorenwahl/shard.lock ./ COPY --from=deps /usr/src/mentorenwahl/lib ./lib ARG BUILD_ENV COPY ./Makefile . COPY ./LICENSE . COPY ./db ./db COPY --from=public /usr/src/public/dist ./public COPY --from=templates-html /usr/src/templates/html ./templates/html COPY ./src ./src RUN if [ "${BUILD_ENV}" = "development" ]; then \ make dev; \ else \ make; \ fi RUN if [ "${BUILD_ENV}" = "development" ]; then \ ldd bin/api | tr -s '[:blank:]' '\n' | grep '^/' | \ xargs -I % sh -c 'mkdir -p $(dirname deps%); cp % deps%;'; \ ldd bin/worker | tr -s '[:blank:]' '\n' | grep '^/' | \ xargs -I % sh -c 'mkdir -p $(dirname deps%); cp % deps%;'; \ fi FROM busybox as runner LABEL maintainer="Dominic Grimm " \ org.opencontainers.image.description="Backend of Mentorenwahl" \ org.opencontainers.image.licenses="GPL-3.0" \ org.opencontainers.image.source="https://git.dergrimm.net/mentorenwahl/mentorenwahl" \ org.opencontainers.image.url="https://git.dergrimm.net/mentorenwahl/mentorenwahl" WORKDIR /usr/src/mentorenwahl COPY --from=micrate-builder /usr/src/micrate/bin/micrate ./bin/micrate COPY --from=builder /usr/src/mentorenwahl/db ./db COPY --from=builder /usr/src/mentorenwahl/deps / COPY --from=builder /usr/src/mentorenwahl/bin ./bin EXPOSE 80