-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from ksiuwr/bartacc/ci_config
Add CI config for Google Cloud Run deployment
- Loading branch information
Showing
6 changed files
with
40 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,39 @@ | ||
#!/bin/sh | ||
set -eu | ||
|
||
PROJECT_ID="<put Google Cloud Project ID here>" | ||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 <GCP Project ID>" | ||
exit 1 | ||
fi | ||
|
||
PROJECT_ID="$1" | ||
REPO_NAME=zosia-repo | ||
REGION=europe-central2 | ||
REGION=europe-west4 | ||
REPO_HOSTNAME=$REGION-docker.pkg.dev | ||
IMAGE_NAME=zosia_prod | ||
|
||
IMAGE_URL=$REPO_HOSTNAME/$PROJECT_ID/$REPO_NAME/$IMAGE_NAME:latest | ||
|
||
# Configure gcloud and docker to be able to push to the Google Container Registry | ||
echo "[1] Configuring gcloud and docker to be able to push to the Google Container Registry" | ||
gcloud config set project $PROJECT_ID | ||
gcloud config set compute/zone $REGION | ||
gcloud auth configure-docker $REPO_HOSTNAME | ||
|
||
# Build and push the image | ||
echo "[2] Building and pushing the image" | ||
docker build --target prod -t $IMAGE_URL . | ||
docker push $IMAGE_URL | ||
|
||
# Run the migration job | ||
echo "[3] Running migrations" | ||
gcloud run jobs update migrate --region=$REGION --image $IMAGE_URL | ||
gcloud run jobs execute migrate --wait --region=$REGION | ||
|
||
# Run the collectstatic job which will collect all the static files into GCS bucket | ||
echo "[4] Collecting static files into a GCS bucket" | ||
gcloud run jobs update collectstatic --region=$REGION --image $IMAGE_URL | ||
gcloud run jobs execute collectstatic --wait --region=$REGION | ||
|
||
# Deploy new service revision with the new image | ||
echo "[5] Updating createsuperuser job to use the new image" | ||
gcloud run jobs update createsuperuser --region=$REGION --image $IMAGE_URL | ||
|
||
echo "[6] Deploying the new image" | ||
gcloud run services update zosia --region $REGION --image $IMAGE_URL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
set -eu | ||
|
||
# This script creates a superuser based on the environment variables: | ||
# DJANGO_SUPERUSER_USERNAME | ||
# DJANGO_SUPERUSER_EMAIL | ||
# DJANGO_SUPERUSER_PASSWORD | ||
|
||
python manage.py createsuperuser --noinput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters