Skip to content

Commit

Permalink
ref(deploy): allow an external mariadb database
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavovalverde committed Jul 11, 2024
1 parent 1c13af4 commit ccf4bbb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
28 changes: 17 additions & 11 deletions .github/workflows/sub-cloudrun-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ on:
image_digest:
required: true
type: string
description: 'The image digest to deploy'
description: The image digest to deploy
project_id:
required: true
type: string
description: 'The project to deploy to'
description: The project to deploy to
region:
required: true
type: string
description: 'The region to deploy to'
description: The region to deploy to
environment:
required: false
type: string
description: 'The environment to deploy to'
description: The environment to deploy to
min_instances:
required: false
type: string
description: 'The minimum number of instances to deploy'
description: The minimum number of instances to deploy
max_instances:
required: false
type: string
description: 'The maximum number of instances to deploy'
description: The maximum number of instances to deploy
cpu:
required: false
type: string
description: 'The number of CPUs to use for the service'
description: The number of CPUs to use for the service
memory:
required: false
type: string
description: 'The amount of memory to use for the service'
description: The amount of memory to use for the service

jobs:
versioning:
Expand Down Expand Up @@ -69,8 +69,8 @@ jobs:
name: ${{ inputs.environment }}
url: ${{ steps.deploy.outputs.url }}
permissions:
contents: 'read'
id-token: 'write'
contents: read
id-token: write
steps:
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
Expand All @@ -95,6 +95,12 @@ jobs:
gcloud_component: alpha
env_vars: |
REPLICA_URL=${{ vars.REPLICA_URL }}
UPTIME_KUMA_DB_TYPE=${{ vars.UPTIME_KUMA_DB_TYPE }}
UPTIME_KUMA_DB_HOSTNAME=${{ vars.UPTIME_KUMA_DB_HOSTNAME }}
UPTIME_KUMA_DB_PORT=${{ vars.UPTIME_KUMA_DB_PORT }}
UPTIME_KUMA_DB_NAME=${{ vars.UPTIME_KUMA_DB_NAME }}
UPTIME_KUMA_DB_USERNAME=${{ vars.UPTIME_KUMA_DB_USERNAME }}
UPTIME_KUMA_DB_PASSWORD=${{ secrets.UPTIME_KUMA_DB_PASSWORD }}
env_vars_update_strategy: overwrite
# secrets: |
flags: |
Expand All @@ -104,7 +110,7 @@ jobs:
--memory=${{ inputs.memory }}
--service-account=${{ vars.GCP_BUCKET_SA }}
--add-volume=name=files,type=in-memory
--add-volume-mount=volume=files,mount-path=/data
--add-volume-mount=volume=files,mount-path=/app/data
--network=projects/zfnd-dev-net-spoke-0/global/networks/dev-spoke-0
--subnet=projects/zfnd-dev-net-spoke-0/regions/us-east1/subnetworks/dev-default-ue1
Expand Down
4 changes: 3 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ FROM base AS runner
COPY --from=litestream/litestream:0.3.13 /usr/local/bin/litestream /usr/local/bin/litestream

# Create data directory (although this will likely be mounted too) as some services won't mount it.
RUN mkdir -p ${DATA_DIR}
RUN mkdir -p "${DATA_DIR}"

EXPOSE ${PORT}

Expand All @@ -38,4 +38,6 @@ HEALTHCHECK --interval=60s --timeout=30s --start-period=180s --retries=5 CMD ext
COPY etc/litestream.yml /etc/litestream.yml
COPY scripts/run.sh /scripts/run.sh

USER node

CMD [ "/scripts/run.sh" ]
10 changes: 7 additions & 3 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
set -e

# Restore the database if it does not already exist.
if [[ -f "${DB_PATH}" ]]; then
if [[ -f "${DB_PATH}" || "${UPTIME_KUMA_DB_TYPE}" != 'mariadb' ]]; then
echo "Database already exists, skipping restore"
else
echo "No database found, restoring from replica if exists"
litestream restore -if-replica-exists -o "${DB_PATH}" "${REPLICA_URL}"
fi

# Run litestream with your app as the subprocess.
exec litestream replicate -exec "node server/server.js"
if [[ "${UPTIME_KUMA_DB_TYPE}" != 'mariadb' ]]; then
exec node server/server.js
else
# Run litestream with your app as the subprocess.
exec litestream replicate -exec "node server/server.js"
fi

0 comments on commit ccf4bbb

Please sign in to comment.