Skip to content

irab/medusa-container-build

Repository files navigation

Building containerised Medusa images for production and development use

Four core components are required for a full Medusa backend deployment:

  • Admin UI
  • Backend Server running Store and Admin APIs
  • A Redis instance as an Eventbus
  • A Postgres instance with an initialised DB

This is a work in progress and "works on my machine" and has not been tested on any other system.

Prerequisites and environment setup

You need to have yarn install correctly. On Debian Bookworm ensure:

  1. Docker Desktop installed
  2. sudo apt install nodejs npm - probably some other things as well??
  3. yarn set version berry - Berry is needed to run dlx command. Classic is needed in the containers.
  4. Google Cloud Storage and service account to host uploaded files #TODO_DOCS
  5. Stripe API Key and frontend setup with Publishable Key #TODO_DOCS
  6. SendGrid API Key and template configured (requires Redis) #TODO_DOCS

Build Steps

Run build.sh, which uses the medusa-cli tool (version pinned) to install the medusa directory, builds the Backend and Admin images and runs them with docker compose up.

Medusa could be run off the same image and container but I'm trying to them running seperately so I've got different medusa-config.js files for each to test a few things.

There is a seed.json file that initialised the

Accessing Admin and API Endpoints

Admin Dashboard: http://localhost:7001/adminapp/ - the admin user and password is created in medusa.sh

API endpoint: http://localhost:9000

Test the API endpoint with something like this curl --location 'http://localhost:9000/store/products' --header 'Accept: application/json' | jq (assuming you have jq installed)

Minio

Minio is an S3 compatible file storage service that integrates with MedusaJS for importing and export of data such as orders or products.

See here for the NPM package and here for official plugin docs.

Exporting orders requires MINIO_PRIVATE_BUCKET to be set and will not work without it being present in medusa-config.js, as sensitive customer data should not be exported into a public bucket.

Troubleshooting

Note that the Admin image is built from node:lts which has /bin/bash installed and the backend image is build from alpine, which has /bin/sh as the default shell.

medusa.sh initially seeds the DB on first run but the container will fail on second boot due to data and a user already existing. I need to add some logic but I fiddle with this file so much I just edit and docker compose down backend && docker compose up backend. Also the seed.json contains data for my personal project, edit as needed...
# Exec into the admin container
docker compose exec backend /bin/bash

# Exec into the backend container
docker compose exec backend /bin/sh

# Shell on disposable container using the last build of the backend image
docker compose build backend
docker run -it $(docker image ls backend -q) /bin/sh

# Delete all containers including postgres and redis state
docker compose down

Note: Postgres database state is running in Docker. Don't expect it to exist after the container is stopped.

Unsure what version of Medusa is actually installed by medusa-cli, as this is does not seem configurable?! 😒

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published