diff --git a/contexts/berta-bot/Dockerfile b/contexts/berta-bot/Dockerfile index 808b566..36254a3 100644 --- a/contexts/berta-bot/Dockerfile +++ b/contexts/berta-bot/Dockerfile @@ -2,7 +2,7 @@ FROM node:16 # This is set to disable caching after this line when there are new commits (./scripts/validate-cache.sh) -ARG COMMIT_HASH=1c08100d37dd996505da8b56fe9b879b65b73aa2 +ARG COMMIT_HASH=b49b062c2cfb6cb326e50d8fdafe6e6a0bfd2f11 WORKDIR /usr/src/app diff --git a/contexts/cards/Dockerfile b/contexts/cards/Dockerfile new file mode 100644 index 0000000..1017615 --- /dev/null +++ b/contexts/cards/Dockerfile @@ -0,0 +1,44 @@ +# Stage one - build the app +FROM rust:1.76 as rustbuilder + +# This is set to disable caching after this line when there are new commits (./scripts/validate-cache.sh) +ARG COMMIT_HASH=95ce4cfedd21e9e6d099ce9fa7fc0d6987da342e + +ARG DATABASE_URL +ARG UUID + +RUN apt-get update && apt-get install -y git + +WORKDIR /usr/src + +RUN git clone -b main --single-branch https://github.com/glencoden/cards-backend.git . + +RUN cargo --config ${DATABASE_URL} +RUN cargo --config ${UUID} + +RUN cargo build --release + +# Stage two - generate tailwind css +FROM node:18 as nodebuilder + +WORKDIR /usr/src + +COPY --from=rustbuilder /usr/src . + +RUN npm install --production=false && npm run tailwind:build + +# Stage three - run the app +FROM debian:bookworm-slim + +ARG DATABASE_URL +ARG UUID + +ENV DATABASE_URL=${DATABASE_URL} +ENV UUID=${UUID} + +RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/* + +COPY --from=rustbuilder /usr/src/target/release/cards-backend . +COPY --from=nodebuilder /usr/src/assets /assets + +CMD ["./cards-backend"] diff --git a/contexts/cards/scripts/validate-cache.sh b/contexts/cards/scripts/validate-cache.sh new file mode 100644 index 0000000..0ed3b17 --- /dev/null +++ b/contexts/cards/scripts/validate-cache.sh @@ -0,0 +1,20 @@ +# fetch remote commit info +git_response=$(git ls-remote https://github.com/glencoden/cards-backend.git | egrep 'main|merge') + +# parse for commit hash +parsed_response=$(echo "$git_response" | tr '\t' ' ') +commit_hash=$(echo "$parsed_response" | cut -d' ' -f1) + +# store the exit status of the git command in a variable +git_exit_status=$? + +if [ $git_exit_status -eq 0 ]; then + sed -i "" -e "5s/.*/ARG COMMIT_HASH=$commit_hash/" contexts/cards/Dockerfile +else + echo "git command failed" +fi + +# if the commit hash is no option, you can invalidate docker cache every run with a timestamp: + +# cache_time=$(date +%s) +# sed -i "" -e "6s/.*/ARG CACHE_TIME=$cache_time/" contexts/tsc/Dockerfile \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9e76fee..35db823 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,8 +30,6 @@ services: volumes: - ${STATIC_DIR}/tsc/build:/usr/src/app/static environment: - VIRTUAL_HOST: ${HOST_TSC} - LETSENCRYPT_HOST: ${HOST_TSC} API_DB_NAME: ${POSTGRES_DATABASE_TSC} AUTH_DB_NAME: ${POSTGRES_DATABASE_TSC_AUTH} DB_USER: ${POSTGRES_USER} @@ -39,10 +37,26 @@ services: DB_HOST: db ADMIN_USERNAME: ${ADMIN_USERNAME} ADMIN_PASSWORD: ${ADMIN_PASSWORD} + VIRTUAL_HOST: ${HOST_TSC} + LETSENCRYPT_HOST: ${HOST_TSC} ports: - "3200:5555" container_name: tsc + cards: + build: + context: contexts/cards + args: + DATABASE_URL: ${CARDS_DATABASE_URL} + UUID: ${CARDS_UUID} + restart: always + environment: + VIRTUAL_HOST: ${HOST_CARDS} + LETSENCRYPT_HOST: ${HOST_CARDS} + ports: + - "3250:3000" + container_name: cards + berta-bot: build: context: contexts/berta-bot @@ -63,9 +77,6 @@ services: context: contexts/looney-api restart: always environment: - VIRTUAL_HOST: ${HOST_LOONEY_API} - VIRTUAL_PORT: 5555 - LETSENCRYPT_HOST: ${HOST_LOONEY_API} REPERTOIRE_DB_NAME: ${POSTGRES_DATABASE_LOONEY_REPERTOIRE} LIVE_DB_NAME: ${POSTGRES_DATABASE_LOONEY_LIVE} AUTH_DB_NAME: ${POSTGRES_DATABASE_LOONEY_API_AUTH} @@ -79,6 +90,9 @@ services: GOOGLE_CALENDAR_ID: ${GOOGLE_CALENDAR_ID} GOOGLE_PRIVATE_KEY_BASE64: ${GOOGLE_PRIVATE_KEY_BASE64} GOOGLE_CLIENT_EMAIL: ${GOOGLE_CLIENT_EMAIL} + VIRTUAL_HOST: ${HOST_LOONEY_API} + VIRTUAL_PORT: 5555 + LETSENCRYPT_HOST: ${HOST_LOONEY_API} ports: - "3400:5555" container_name: looney-api diff --git a/package.json b/package.json index 058cee0..e226035 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "db:init": "bash scripts/init-database.sh", "db:backup": "bash scripts/backup-database.sh", "db:restore": "bash scripts/restore-database.sh", - "cache:validate": "bash contexts/mailer/scripts/validate-cache.sh && bash contexts/tsc/scripts/validate-cache.sh && bash contexts/berta-bot/scripts/validate-cache.sh && bash contexts/looney-api/scripts/validate-cache.sh" + "cache:validate": "bash contexts/mailer/scripts/validate-cache.sh && bash contexts/tsc/scripts/validate-cache.sh && bash contexts/cards/scripts/validate-cache.sh && bash contexts/berta-bot/scripts/validate-cache.sh && bash contexts/looney-api/scripts/validate-cache.sh" }, "repository": { "type": "git",