Skip to content

Commit

Permalink
Improve run modes
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltrolezi committed Oct 8, 2024
1 parent ccf7439 commit 430b62f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 2 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ if [ ! -d "vendor" ] || [ -z "$(ls -A vendor)" ]; then

php artisan key:generate --ansi
php artisan migrate --seed
else
php artisan migrate --seed
fi
fi

Expand Down
26 changes: 12 additions & 14 deletions gcp/tools/deploy-job.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,31 @@ JOB_DEFINITION="$SCRIPT_DIR/../cloud-run/job.yaml"

# Load environment variables from .env file if it exists
if [ -f "$SCRIPT_DIR/../../.env" ]; then
export $(cat "$SCRIPT_DIR/../../.env" | grep -v '^#' | xargs)
export $(grep -v '^#' "$SCRIPT_DIR/../../.env" | xargs)
fi

# Get the RUN_MODE from the first argument
RUN_MODE=$1

# Define command case RUN_MODE=command
RUN_MODE_COMMAND="sleep 5 && php artisan migrate --seed -vvv"
RUN_MODE_COMMAND="sleep 5 \&\& php artisan migrate --seed -vvv"

# Copy the template to a new job.yaml file
cp "$SCRIPT_DIR/../cloud-run/job.template.yaml" $JOB_DEFINITION
cp "$SCRIPT_DIR/../cloud-run/job.template.yaml" "$JOB_DEFINITION"

# Replace placeholders
sed -i "s|<RUN_MODE>|$RUN_MODE|" $JOB_DEFINITION
sed -i "s|<RUN_MODE_COMMAND>|$RUN_MODE_COMMAND|" $JOB_DEFINITION
sed -i "s|<GCP_PROJECT_NUMBER>|$GCP_PROJECT_NUMBER|" $JOB_DEFINITION
sed -i "s|<GCP_REGION>|$GCP_REGION|" $JOB_DEFINITION
sed -i "s|<GCP_CLOUD_RUN_SERVICE>|$GCP_CLOUD_RUN_SERVICE|" $JOB_DEFINITION
sed -i "s|<DOCKER_IMAGE>|$GCP_AR_REPOSITORY/app:latest|" $JOB_DEFINITION
sed -i "s|<RUN_MODE>|$RUN_MODE|g" "$JOB_DEFINITION"
sed -i "s|<RUN_MODE_COMMAND>|$RUN_MODE_COMMAND|g" "$JOB_DEFINITION"
sed -i "s|<GCP_PROJECT_NUMBER>|$GCP_PROJECT_NUMBER|g" "$JOB_DEFINITION"
sed -i "s|<GCP_REGION>|$GCP_REGION|g" "$JOB_DEFINITION"
sed -i "s|<GCP_CLOUD_RUN_SERVICE>|$GCP_CLOUD_RUN_SERVICE|g" "$JOB_DEFINITION"
sed -i "s|<DOCKER_IMAGE>|$GCP_AR_REPOSITORY/app:latest|g" "$JOB_DEFINITION"

# Deploy the job using the modified job.yaml
gcloud beta run jobs replace $JOB_DEFINITION --region $GCP_REGION --project $GCP_PROJECT_ID
gcloud beta run jobs replace "$JOB_DEFINITION" --region "$GCP_REGION" --project "$GCP_PROJECT_ID"

# Execute the job after replacing it
gcloud beta run jobs execute "$GCP_CLOUD_RUN_SERVICE-task-runner" --region $GCP_REGION --project $GCP_PROJECT_ID
gcloud beta run jobs execute "$GCP_CLOUD_RUN_SERVICE-task-runner" --region "$GCP_REGION" --project "$GCP_PROJECT_ID"

# Clean up the temporary job.yaml file
rm "$SCRIPT_DIR/../cloud-run/job.yaml"


rm "$SCRIPT_DIR/../cloud-run/job.yaml"

0 comments on commit 430b62f

Please sign in to comment.