mentorenwahl/backend/Dockerfile

87 lines
3.2 KiB
Docker
Raw Permalink Normal View History

2022-02-10 07:43:47 +00:00
# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
# Copyright (C) 2022 Dominic Grimm
2022-03-07 13:06:02 +00:00
#
2022-02-10 07:43:47 +00:00
# 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.
2022-03-07 13:06:02 +00:00
#
2022-02-10 07:43:47 +00:00
# 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.
2022-03-07 13:06:02 +00:00
#
2022-02-10 07:43:47 +00:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2023-03-09 17:19:53 +00:00
FROM docker.io/crystallang/crystal:1.7.3-alpine as crystal
FROM docker.io/tdewolff/minify:latest as minify
2023-01-29 10:49:13 +00:00
FROM crystal as micrate-deps
2022-10-31 08:47:26 +00:00
WORKDIR /usr/src/micrate
2022-04-14 16:22:07 +00:00
COPY ./micrate/shard.yml ./micrate/shard.lock ./
2022-01-20 16:32:15 +00:00
RUN shards install --production
2022-01-08 12:29:22 +00:00
2023-01-29 10:49:13 +00:00
FROM crystal as micrate-builder
2022-10-31 08:47:26 +00:00
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
2022-04-14 16:22:07 +00:00
COPY ./micrate/src ./src
RUN shards build --release --static --verbose -s -p -t
2023-01-29 15:04:47 +00:00
FROM minify as public
2022-10-31 08:47:26 +00:00
WORKDIR /usr/src/public
COPY ./public ./src
2022-07-28 12:05:10 +00:00
RUN minify -r -o ./dist ./src
2023-01-29 10:49:13 +00:00
FROM crystal as deps
2022-10-31 08:47:26 +00:00
WORKDIR /usr/src/mentorenwahl
2022-04-14 16:22:07 +00:00
COPY ./shard.yml ./shard.lock ./
RUN shards install --production
2023-01-29 15:04:47 +00:00
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"'
2023-01-29 10:49:13 +00:00
FROM crystal as builder
2022-10-31 08:47:26 +00:00
WORKDIR /usr/src/mentorenwahl
RUN apk add --no-cache pcre2-dev
2022-11-21 18:48:53 +00:00
RUN mkdir deps
2022-10-31 08:47:26 +00:00
COPY --from=deps /usr/src/mentorenwahl/shard.yml /usr/src/mentorenwahl/shard.lock ./
COPY --from=deps /usr/src/mentorenwahl/lib ./lib
2022-11-21 18:48:53 +00:00
ARG BUILD_ENV
COPY ./Makefile .
2022-11-21 18:48:53 +00:00
COPY ./LICENSE .
2022-04-14 16:22:07 +00:00
COPY ./db ./db
2022-10-31 08:47:26 +00:00
COPY --from=public /usr/src/public/dist ./public
2023-01-29 15:04:47 +00:00
COPY --from=templates-html /usr/src/templates/html ./templates/html
2022-11-21 18:48:53 +00:00
COPY ./src ./src
2022-01-10 16:53:38 +00:00
RUN if [ "${BUILD_ENV}" = "development" ]; then \
2023-03-05 13:27:50 +00:00
make dev; \
2023-02-25 13:38:14 +00:00
else \
make; \
2022-10-31 08:47:26 +00:00
fi
2023-03-05 13:27:50 +00:00
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
2023-02-05 16:25:03 +00:00
FROM busybox as runner
2022-11-21 18:48:53 +00:00
LABEL maintainer="Dominic Grimm <dominic@dergrimm.net>" \
org.opencontainers.image.description="Backend of Mentorenwahl" \
2022-11-25 22:21:21 +00:00
org.opencontainers.image.licenses="GPL-3.0" \
2022-11-21 18:48:53 +00:00
org.opencontainers.image.source="https://git.dergrimm.net/mentorenwahl/mentorenwahl" \
org.opencontainers.image.url="https://git.dergrimm.net/mentorenwahl/mentorenwahl"
2023-02-01 17:36:39 +00:00
WORKDIR /usr/src/mentorenwahl
2022-10-31 08:47:26 +00:00
COPY --from=micrate-builder /usr/src/micrate/bin/micrate ./bin/micrate
2022-11-21 18:48:53 +00:00
COPY --from=builder /usr/src/mentorenwahl/db ./db
2022-10-31 08:47:26 +00:00
COPY --from=builder /usr/src/mentorenwahl/deps /
2023-03-05 13:27:50 +00:00
COPY --from=builder /usr/src/mentorenwahl/bin ./bin
2022-01-15 19:04:31 +00:00
EXPOSE 80