mentorenwahl/backend/Dockerfile

74 lines
2.7 KiB
Docker
Raw 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/>.
2022-10-31 08:47:26 +00:00
FROM crystallang/crystal:1.6-alpine as micrate-deps
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
2022-10-31 08:47:26 +00:00
FROM crystallang/crystal:1.6-alpine 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
2022-04-14 16:22:07 +00:00
COPY ./micrate/src ./src
RUN shards build --release --static --verbose -s -p -t
FROM tdewolff/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
2022-10-31 08:47:26 +00:00
FROM crystallang/crystal:1.6-alpine as deps
WORKDIR /usr/src/mentorenwahl
2022-04-14 16:22:07 +00:00
COPY ./shard.yml ./shard.lock ./
RUN shards install --production
2022-10-31 08:47:26 +00:00
FROM crystallang/crystal:1.6-alpine as builder
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
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 \
2022-02-07 18:25:18 +00:00
make dev; \
2022-01-10 16:53:38 +00:00
else \
2022-02-07 18:25:18 +00:00
make; \
2022-01-10 16:53:38 +00:00
fi
2022-10-31 08:47:26 +00:00
RUN if [ "${BUILD_ENV}" = "development" ]; then \
ldd bin/backend | tr -s '[:blank:]' '\n' | grep '^/' | \
xargs -I % sh -c 'mkdir -p $(dirname deps%); cp % deps%;'; \
fi
FROM scratch 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"
2022-10-31 08:47:26 +00:00
WORKDIR /
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 /
COPY --from=builder /usr/src/mentorenwahl/bin/backend ./bin/backend
2022-01-15 19:04:31 +00:00
EXPOSE 80
2022-11-21 18:48:53 +00:00
CMD [ "./bin/backend", "run" ]