76 lines
2.7 KiB
Docker
76 lines
2.7 KiB
Docker
# 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 <https://www.gnu.org/licenses/>.
|
|
|
|
FROM docker.io/crystallang/crystal:1.6.2-alpine as crystal
|
|
|
|
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 tdewolff/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 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 ./src ./src
|
|
RUN if [ "${BUILD_ENV}" = "development" ]; then \
|
|
make dev; \
|
|
else \
|
|
make; \
|
|
fi
|
|
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
|
|
LABEL maintainer="Dominic Grimm <dominic@dergrimm.net>" \
|
|
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 /
|
|
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/backend ./bin/backend
|
|
EXPOSE 80
|
|
CMD [ "./bin/backend", "run" ]
|