Deployment stuff
This commit is contained in:
parent
a9468c6970
commit
57859b514f
7 changed files with 194 additions and 3 deletions
6
holycow_backend/.dockerignore
Normal file
6
holycow_backend/.dockerignore
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
|
target/
|
||||||
|
.env
|
||||||
|
.gitignore
|
||||||
|
holycow_backend.iml
|
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
||||||
authors = ["Stefano Pigozzi <me@steffo.eu>"]
|
authors = ["Stefano Pigozzi <me@steffo.eu>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Backend for a Telegram Mini App for match and skill level tracking among players in a group"
|
description = "Backend for a Telegram Mini App for match and skill level tracking among players in a group"
|
||||||
repository = "https://forge.steffo.eu/unimore/tirocinio-canali-steffo-acrate"
|
repository = "https://forge.steffo.eu/starshard/holycow"
|
||||||
license = "EUPL-1.2"
|
license = "EUPL-1.2"
|
||||||
keywords = ["mtg", "openskill", "wenglin", "telegram", "telegram-miniapp"]
|
keywords = ["mtg", "openskill", "wenglin", "telegram", "telegram-miniapp"]
|
||||||
categories = []
|
categories = []
|
||||||
|
|
111
holycow_backend/Dockerfile
Normal file
111
holycow_backend/Dockerfile
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
FROM --platform=${BUILDPLATFORM} rust:1-bookworm AS builder
|
||||||
|
ARG BUILDPLATFORM
|
||||||
|
ARG TARGETPLATFORM
|
||||||
|
|
||||||
|
WORKDIR /usr/src/holycow_backend/
|
||||||
|
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get upgrade --assume-yes
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
mkdir .cargo && \
|
||||||
|
echo '[net]' >> .cargo/config.toml && \
|
||||||
|
echo 'git-fetch-with-cli = true' >> .cargo/config.toml && \
|
||||||
|
echo >> .cargo/config.toml && \
|
||||||
|
if [ "${BUILDPLATFORM}" != "${TARGETPLATFORM}" ]; then \
|
||||||
|
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
|
||||||
|
dpkg --add-architecture amd64; \
|
||||||
|
apt-get update; \
|
||||||
|
apt-get install --assume-yes gcc-x86-64-linux-gnu; \
|
||||||
|
echo '[target.x86_64-unknown-linux-gnu]' >> .cargo/config.toml; \
|
||||||
|
echo 'linker = "x86-64-linux-gnu-gcc"' >> .cargo/config.toml; \
|
||||||
|
echo >> .cargo/config.toml; \
|
||||||
|
fi && \
|
||||||
|
if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
|
||||||
|
dpkg --add-architecture arm64; \
|
||||||
|
apt-get update; \
|
||||||
|
apt-get install --assume-yes gcc-aarch64-linux-gnu; \
|
||||||
|
echo '[target.aarch64-unknown-linux-gnu]' >> .cargo/config.toml; \
|
||||||
|
echo 'linker = "aarch64-linux-gnu-gcc"' >> .cargo/config.toml; \
|
||||||
|
echo >> .cargo/config.toml; \
|
||||||
|
fi && \
|
||||||
|
if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
|
||||||
|
dpkg --add-architecture armhf; \
|
||||||
|
apt-get update; \
|
||||||
|
apt-get install --assume-yes gcc-arm-linux-gnueabihf; \
|
||||||
|
echo '[target.armv7-unknown-linux-gnueabihf]' >> .cargo/config.toml; \
|
||||||
|
echo 'linker = "arm-linux-gnueabihf-gcc"' >> .cargo/config.toml; \
|
||||||
|
echo >> .cargo/config.toml; \
|
||||||
|
fi \
|
||||||
|
fi
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
|
||||||
|
RUSTTARGET=x86_64-unknown-linux-gnu; \
|
||||||
|
fi && \
|
||||||
|
if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
|
||||||
|
RUSTTARGET=aarch64-unknown-linux-gnu; \
|
||||||
|
fi && \
|
||||||
|
if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
|
||||||
|
RUSTTARGET=armv7-unknown-linux-gnueabihf; \
|
||||||
|
fi && \
|
||||||
|
rustup target add ${RUSTTARGET}
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
|
||||||
|
apt-get install --assume-yes libpq5:amd64 libpq-dev:amd64 openssl:amd64 libssl-dev:amd64 pkg-config:amd64; \
|
||||||
|
elif [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
|
||||||
|
apt-get install --assume-yes libpq5:arm64 libpq-dev:arm64 openssl:arm64 libssl-dev:arm64 pkg-config:arm64; \
|
||||||
|
elif [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
|
||||||
|
apt-get install --assume-yes libpq5:armhf libpq-dev:armhf openssl:armhf libssl-dev:armhf pkg-config:armhf; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
COPY ./ ./
|
||||||
|
|
||||||
|
# This has reached a new level of hack
|
||||||
|
RUN \
|
||||||
|
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
|
||||||
|
RUSTTARGET=x86_64-unknown-linux-gnu; \
|
||||||
|
export TARGET_CC=/usr/bin/x86-64-linux-gnu-gcc; \
|
||||||
|
export TARGET_AR=/usr/bin/x86-64-linux-gnu-ar; \
|
||||||
|
export PKG_CONFIG_SYSROOT_DIR=/usr/lib/x86-64-linux-gnu; \
|
||||||
|
elif [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
|
||||||
|
RUSTTARGET=aarch64-unknown-linux-gnu; \
|
||||||
|
export TARGET_CC=/usr/bin/aarch64-linux-gnu-gcc; \
|
||||||
|
export TARGET_AR=/usr/bin/aarch64-linux-gnu-ar; \
|
||||||
|
export PKG_CONFIG_SYSROOT_DIR=/usr/lib/aarch64-linux-gnu; \
|
||||||
|
elif [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
|
||||||
|
RUSTTARGET=armv7-unknown-linux-gnueabihf; \
|
||||||
|
export TARGET_CC=/usr/bin/arm-linux-gnueabihf-gcc; \
|
||||||
|
export TARGET_AR=/usr/bin/arm-linux-gnueabihf-ar; \
|
||||||
|
export PKG_CONFIG_SYSROOT_DIR=/usr/lib/arm-linux-gnueabihf; \
|
||||||
|
fi && \
|
||||||
|
cargo build --all-features --bins --release --target=${RUSTTARGET}
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
FROM --platform=${TARGETPLATFORM} rust:1-slim-bookworm AS final
|
||||||
|
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get upgrade --assume-yes && \
|
||||||
|
apt-get install --assume-yes libpq5 openssl
|
||||||
|
|
||||||
|
WORKDIR /usr/src/holycow_backend/
|
||||||
|
COPY --from=builder \
|
||||||
|
/usr/src/holycow_backend/target/*/release/holycow_backend \
|
||||||
|
/usr/bin/
|
||||||
|
|
||||||
|
ENTRYPOINT ["holycow_backend"]
|
||||||
|
CMD []
|
||||||
|
|
||||||
|
LABEL org.opencontainers.image.title="Holy Cow (backend)"
|
||||||
|
LABEL org.opencontainers.image.description="Backend for a Telegram Mini App for match and skill level tracking among players in a group"
|
||||||
|
LABEL org.opencontainers.image.licenses="EUPL-1.2"
|
||||||
|
LABEL org.opencontainers.image.url="https://forge.steffo.eu/starshard/holycow"
|
||||||
|
LABEL org.opencontainers.image.authors="Stefano Pigozzi <me@steffo.eu>"
|
||||||
|
|
||||||
|
ENV RUST_LOG="warn,holycow_backend=info"
|
||||||
|
ENV BACKEND_BIND_ADDRESS="0.0.0.0:30001"
|
||||||
|
|
||||||
|
EXPOSE 30001
|
7
holycow_frontend/.dockerignore
Normal file
7
holycow_frontend/.dockerignore
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
|
node_modules/
|
||||||
|
npm-debug.log
|
||||||
|
.next
|
||||||
|
out/
|
||||||
|
.env
|
66
holycow_frontend/Dockerfile
Normal file
66
holycow_frontend/Dockerfile
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
# From https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
|
||||||
|
|
||||||
|
FROM node:18-alpine AS base
|
||||||
|
|
||||||
|
# Install dependencies only when needed
|
||||||
|
FROM base AS deps
|
||||||
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||||
|
RUN apk add --no-cache libc6-compat
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install dependencies based on the preferred package manager
|
||||||
|
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
|
||||||
|
RUN \
|
||||||
|
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
||||||
|
elif [ -f package-lock.json ]; then npm ci; \
|
||||||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
||||||
|
else echo "Lockfile not found." && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Rebuild the source code only when needed
|
||||||
|
FROM base AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Next.js collects completely anonymous telemetry data about general usage.
|
||||||
|
# Learn more here: https://nextjs.org/telemetry
|
||||||
|
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||||
|
# ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
if [ -f yarn.lock ]; then yarn run build; \
|
||||||
|
elif [ -f package-lock.json ]; then npm run build; \
|
||||||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
||||||
|
else echo "Lockfile not found." && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Production image, copy all the files and run next
|
||||||
|
FROM base AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
# Uncomment the following line in case you want to disable telemetry during runtime.
|
||||||
|
# ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
|
RUN adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
|
||||||
|
# Automatically leverage output traces to reduce image size
|
||||||
|
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
ENV PORT=3000
|
||||||
|
|
||||||
|
# server.js is created by next build from the standalone output
|
||||||
|
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
|
||||||
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
CMD ["node", "server.js"]
|
|
@ -1,6 +1,8 @@
|
||||||
import {NextConfig} from "next"
|
import {NextConfig} from "next"
|
||||||
|
|
||||||
|
|
||||||
const nextConfig: NextConfig = {}
|
const nextConfig: NextConfig = {
|
||||||
|
output: "standalone",
|
||||||
|
}
|
||||||
|
|
||||||
export default nextConfig
|
export default nextConfig
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
},
|
},
|
||||||
"license": "EUPL-1.2",
|
"license": "EUPL-1.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@awesome.me/kit-2b1ce28b9d": "^1.0.4",
|
|
||||||
"@steffo/bluelib": "^9.1.0",
|
"@steffo/bluelib": "^9.1.0",
|
||||||
"@types/node": "^22.10.0",
|
"@types/node": "^22.10.0",
|
||||||
"@types/react": "^18.3.12",
|
"@types/react": "^18.3.12",
|
||||||
|
|
Loading…
Reference in a new issue