Vendure eCommerce on Google Cloud Run

Minimal effort

What needs to be done

  • Vendure uses local file system to store assets. Cloud Run doesn’t have persistent local file system
  • Listen to the correct Cloud Run port
  • A MySQL database for Vendure
  • Dockerize the application
  • Deploy to Google Cloud Run

Google Storage

Configure port

apiOptions: {
port: process.env.PORT || 3000
}

MySQL database

  • Create a database and user. Save the host, username, password and database name
  • Set the host, username, password and databasename in vendure-config.ts :
dbConnectionOptions: {
type: ‘mysql’,
synchronize: true,
logging: false,
username: DATABASE_USER,
password: DATABASE_PASSWORD,
host: DATABASE_HOST,
database: DATABASE_NAME,
}

Dockerize the application

# https://github.com/vendure-ecommerce/vendure/issues/458
FROM
node:12

WORKDIR /
usr/src/app

# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY
package*.json ./

RUN
npm ci --only=production

# Bundle app source
COPY
. .

# Run the web service on container startup.
CMD
[ "npm", "start"]
docker build -t eu.gcr.io/your-gcloud-project/your-app .
# Configure docker to use Google authentication
gcloud auth configure-docker -q
docker
push eu.gcr.io/your-gcloud-project/your-app

Deploy

gcloud run deploy shops-test \
--quiet \
--image "eu.gcr.io/your-gcloud-project/your-app:latest" \
--region "europe-west1" \
--platform "managed" \
--allow-unauthenticated \
--memory=1G

Improvements

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store