Skip to content

Instantly share code, notes, and snippets.

View ashmore11's full-sized avatar

Scott Ashmore ashmore11

View GitHub Profile
@ashmore11
ashmore11 / docker-compose.yml
Last active January 19, 2021 20:09
Next Strapi Cloud Run (docker compose cloud sql proxy)
version: "3.7"
services:
next-strapi-cloud-run-cloud-sql-proxy:
container_name: next-strapi-cloud-run-cloud-sql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.19.1
command: /cloud_sql_proxy -instances={Cloud SQL connnection name}=tcp:0.0.0.0:3306 -credential_file=/credentials.json
volumes:
- ./google-credentials.json:/credentials.json
ports:
- 3308:3306
@ashmore11
ashmore11 / pipelines-sync-db.sh
Last active January 19, 2021 21:41
Next Strapi Cloud Run (pipelines sync db bash)
#! /bin/bash
apt-get update && apt-get install default-mysql-client -y
query="SELECT count(*) AS TOTALNUMBEROFTABLES FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'production';"
tableCount=$(mysql -u "$DB_USERNAME" -p"$DB_PASSWORD" -h "$DB_HOST" -s -e "$query")
echo ""
echo "Starting database dump..."
if [[ $tableCount = "0" ]]; then
@ashmore11
ashmore11 / outputs.tf
Last active January 19, 2021 22:08
Next Strapi Cloud Run (terraform outputs)
output "gcp_project_id" {
value = google_project.project.project_id
}
output "local_database_service_account_key_json" {
value = base64decode(google_service_account_key.local_database.private_key)
}
output "cloud_sql_root_user_password" {
value = random_password.cms_sql_root_password.result
@ashmore11
ashmore11 / pipelines-deploy-cms.sh
Last active January 19, 2021 17:48
Next Strapi Cloud Run (pipelines deploy cms)
#! /bin/bash
echo ""
echo "Building and deploying the CMS..."
cd cms || exit
image="eu.gcr.io/$GCLOUD_PROJECT_ID/$BITBUCKET_DEPLOYMENT_ENVIRONMENT"
existing_tags=$(gcloud container images list-tags --filter="tags:cms" --format=json "$image")
@ashmore11
ashmore11 / pipelines-deploy-app.sh
Last active January 19, 2021 17:48
Next Strapi Cloud Run (pipelines deploy app)
#! /bin/bash
echo ""
echo "Building and deploying the app..."
cd app || exit
image="eu.gcr.io/$GCLOUD_PROJECT_ID/$BITBUCKET_DEPLOYMENT_ENVIRONMENT"
existing_tags=$(gcloud container images list-tags --filter="tags:app" --format=json "$image")
@ashmore11
ashmore11 / pipelines-prepare.sh
Last active January 19, 2021 17:49
Next Strapi Cloud Run (pipelines prepare bash)
#! /bin/bash
# Activate Google Serice Account responsible for deployments
echo "$GCLOUD_SERVICE_ACCOUNT_KEY" > .service-account-key.json
gcloud auth activate-service-account --key-file .service-account-key.json
# Set te project in gcloud so it knows which project to interact with
gcloud config set project "$GCLOUD_PROJECT_ID"
# Authorize docker so we can push images to Google Container Registry
@ashmore11
ashmore11 / bitbucket-pipelines.yml
Last active January 19, 2021 18:02
Next Strapi Cloud Run (pipelines)
pipelines:
branches:
master:
- step:
name: Deploy to Production
deployment: production
image: google/cloud-sdk:latest
services:
- docker
caches:
@ashmore11
ashmore11 / database.json
Last active January 19, 2021 18:44
Next Strapi Cloud Run (database production)
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "bookshelf",
"settings": {
"client": "mysql",
"database": "${process.env.DB_NAME}",
"username": "${process.env.DB_USERNAME}",
"password": "${process.env.DB_PASSWORD}",
@ashmore11
ashmore11 / Dockerfile
Created January 15, 2021 11:01
Next Strapi Cloud Run (Docker app)
FROM node:12-alpine
WORKDIR /usr/src/app
ARG CMS_GRAPHQL_URL
ENV CMS_GRAPHQL_URL=$CMS_GRAPHQL_URL
ENV NODE_ENV=production
COPY package*.json ./
@ashmore11
ashmore11 / Dockerfile
Created January 15, 2021 11:00
Next Strapi Cloud Run (Dockerfile cms)
FROM node:12-alpine
WORKDIR /usr/src/cms
ENV NODE_ENV=production
COPY package*.json ./
RUN npm ci --production && npm cache clean --force
COPY . .