Skip to content

Commit

Permalink
make update re-run after delay
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeBu committed Feb 28, 2025
1 parent 5f9e179 commit 04f994d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Dockerfile.api
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ WORKDIR /app
COPY package.json yarn.lock ./
COPY api/package.json api/
COPY api/.env.sh api/
COPY api/update-then-wait.sh api/

RUN yarn install --frozen-lockfile

COPY turbo.json ./
COPY api/ api/

WORKDIR /app/api
RUN chmod +x /app/api/update-then-wait.sh
RUN yarn build

CMD ["yarn", "start"]
1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"build": "tsc",
"start": "yarn db:up && dotenv -e ../.env -- node dist/src/entrypoints/start-api.js",
"update": "dotenv -e ../.env -- node dist/src/entrypoints/update.js",
"update-then-wait": "./update-then-wait.sh",
"import": "dotenv -e ../.env -- node dist/src/entrypoints/import.js",
"_format": "prettier \"**/*.{ts,tsx,json,md}\"",
"format": "yarn run _format --write",
Expand Down
2 changes: 1 addition & 1 deletion api/src/entrypoints/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { env } from "../env";
import { startUpdateService } from "../rpc/update";

startUpdateService(env);
startUpdateService(env).then(() => process.exit(0));
23 changes: 23 additions & 0 deletions api/update-then-wait.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
set -e

# Get delay from first argument or use default of 0 minutes (no delay)
DELAY_IN_MINUTES=${1:-0}

# Convert minutes to seconds
DELAY_IN_SECONDS=$((DELAY_IN_MINUTES * 60))

START_DATETIME=$(date "+%Y-%m-%d %H:%M:%S")

echo "Starting update at ${START_DATETIME}"
# Run the update command
yarn update

END_DATETIME=$(date "+%Y-%m-%d %H:%M:%S")

# Always wait for the specified delay before exiting
# This will cause Docker to wait before restarting the container
echo "Update completed at ${END_DATETIME}, waiting the delay of ${DELAY_IN_MINUTES} minutes before quitting"
sleep ${DELAY_IN_SECONDS}

exit 0
17 changes: 17 additions & 0 deletions docker-compose.preprod.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
services:
api:
depends_on:
- postgres
build:
context: "."
dockerfile: Dockerfile.api
env_file: .env
restart: unless-stopped
command: yarn start

update:
depends_on:
- api
- postgres
build:
context: "."
dockerfile: Dockerfile.api
env_file: .env
restart: always
# runs every 4 hours (240 minutes)
command: yarn update-then-wait 240

web:
depends_on:
- api
build:
context: "."
dockerfile: Dockerfile.web
Expand Down
12 changes: 10 additions & 2 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
services:
api:
depends_on:
- postgres
build:
context: "."
dockerfile: Dockerfile.api
Expand All @@ -8,14 +10,20 @@ services:
command: yarn start

update:
depends_on:
- api
- postgres
build:
context: "."
dockerfile: Dockerfile.api
env_file: .env
restart: unless-stopped
command: yarn update
restart: always
# runs every 4 hours (240 minutes)
command: yarn update-then-wait 240

web:
depends_on:
- api
build:
context: "."
dockerfile: Dockerfile.web
Expand Down
2 changes: 1 addition & 1 deletion web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<link rel="shortcut icon" href="%PUBLIC_URL%/dsfr/favicon/favicon.ico?v=1.13.0" type="image/x-icon" />
<link rel="manifest" href="%PUBLIC_URL%/dsfr/favicon/manifest.webmanifest?v=1.13.0" crossorigin="use-credentials" />

<link rel="stylesheet" href="%PUBLIC_URL%/dsfr/utility/icons/icons.min.css?v=1.13.0" />
<link rel="stylesheet" href="%PUBLIC_URL%/dsfr/utility/icons/icons.min.css?hash=3a4b2f87" />
<link rel="stylesheet" href="%PUBLIC_URL%/dsfr/dsfr.min.css?v=1.13.0" />

<%
Expand Down

0 comments on commit 04f994d

Please sign in to comment.