Skip to content

Commit

Permalink
fix: startup.sh optional sourcing in run.sh (#1914)
Browse files Browse the repository at this point in the history
* fix: startup script and shutdown script loading

* fix: refactor for sync startup script, instead of async metadata startup script
  • Loading branch information
Ziinc authored Jan 10, 2024
1 parent fbd26ca commit 032da4f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
17 changes: 8 additions & 9 deletions cloudbuild/prod/pre-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ steps:
- --scopes=https://www.googleapis.com/auth/cloud-platform
- --tags=phoenix-http,https-server
- --metadata-from-file=shutdown-script=./cloudbuild/shutdown.sh
- --metadata-from-file=startup-script=./cloudbuild/startup.sh
# needed for enabling node-problem-detector, explicitly enable logging
- --metadata=google-monitoring-enabled=true,google-logging-enabled=true
- --container-image=${_CONTAINER_IMAGE}
Expand Down Expand Up @@ -51,13 +50,13 @@ steps:
- --version=template=projects/logflare-232118/global/instanceTemplates/${_TEMPLATE_NAME}

substitutions:
_CLUSTER: canary
_COOKIE: default-${_CLUSTER}
_INSTANCE_GROUP: instance-group-prod-canary
_IMAGE_TAG: $SHORT_SHA
_TEMPLATE_NAME: logflare-prod-${_NORMALIZED_IMAGE_TAG}
_CONTAINER_IMAGE: gcr.io/logflare-232118/logflare_app:${_IMAGE_TAG}
_CLUSTER: canary
_COOKIE: default-${_CLUSTER}
_INSTANCE_GROUP: instance-group-prod-canary
_IMAGE_TAG: $SHORT_SHA
_TEMPLATE_NAME: logflare-prod-${_NORMALIZED_IMAGE_TAG}
_CONTAINER_IMAGE: gcr.io/logflare-232118/logflare_app:${_IMAGE_TAG}
timeout: 1800s
options:
dynamicSubstitutions: true
substitutionOption: "ALLOW_LOOSE"
dynamicSubstitutions: true
substitutionOption: "ALLOW_LOOSE"
2 changes: 2 additions & 0 deletions cloudbuild/secret_setup.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ COPY db-client-cert.pem db-client-cert.pem
COPY db-client-key.pem db-client-key.pem
COPY db-server-ca.pem db-server-ca.pem

COPY ./cloudbuild/startup.sh /opt/app/rel/logflare/bin/startup.sh

ENTRYPOINT ["tini", "--"]

CMD ["sh", "run.sh"]
1 change: 0 additions & 1 deletion cloudbuild/staging/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ steps:
- --tags=phoenix-http,https-server
- --container-image=${_CONTAINER_IMAGE}
- --metadata-from-file=shutdown-script=./cloudbuild/shutdown.sh
- --metadata-from-file=startup-script=./cloudbuild/startup.sh
# needed for enabling node-problem-detector, explicitly enable logging
- --metadata=google-monitoring-enabled=true,google-logging-enabled=true
- --container-privileged
Expand Down
5 changes: 2 additions & 3 deletions cloudbuild/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ sleep 15
# add in monitoring cpu timer interrupts
sysctl -w net.ipv4.tcp_keepalive_time=60 net.ipv4.tcp_keepalive_intvl=60 net.ipv4.tcp_keepalive_probes=5 kernel.nmi_watchdog=1

LOGFLARE_NODE_HOST=$(curl \
export LOGFLARE_NODE_HOST=$(curl \
-s "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip" \
-H "Metadata-Flavor: Google")

# append to secrets file
echo "$LOGFLARE_NODE_HOST" >> /tmp/.secrets.env
echo "LOGFLARE_NODE_HOST from GCP is: $LOGFLARE_NODE_HOST"
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ services:
source: ${PWD}/gcloud.json
target: /opt/app/rel/logflare/bin/gcloud.json
read_only: true
# uncomment if you want to add a startup script
# - type: bind
# source: ${PWD}/cloudbuild/startup.sh
# target: /opt/app/rel/logflare/bin/startup.sh
# read_only: true
depends_on:
- db

Expand Down
7 changes: 7 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#! /bin/sh

# maybe run a startup script
if [ -f ./startup.sh ]
then
echo 'startup.sh file present, sourcing...';
. ./startup.sh;
fi

# load secrets conditionally
if [ -f /tmp/.secrets.env ]
then
Expand Down

0 comments on commit 032da4f

Please sign in to comment.