Skip to content

Commit

Permalink
Merge pull request #113 from glencoden/develop
Browse files Browse the repository at this point in the history
add cards app
  • Loading branch information
glencoden authored Feb 22, 2024
2 parents fdfdaff + 14d7a1b commit d7a46a1
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 7 deletions.
2 changes: 1 addition & 1 deletion contexts/berta-bot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 44 additions & 0 deletions contexts/cards/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
20 changes: 20 additions & 0 deletions contexts/cards/scripts/validate-cache.sh
Original file line number Diff line number Diff line change
@@ -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
24 changes: 19 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,33 @@ 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}
DB_PASSWORD: ${POSTGRES_PASSWORD}
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
Expand All @@ -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}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d7a46a1

Please sign in to comment.