Strapi + Gatby Workflow in parallel?

Hello, I’m trying to set up a CI job for a test project of mine.
The project uses Gatsby and Strapi. The problem is I don’t know how to have the strapi part running as my frontend “gatsby build” collects data from the local strapi backend.

Here is my config:

config.yml

version: 2.1

executors:
node:
parameters:
image:
type: string
# First 10.x LTS release, but old Yarn
default: “12.13.0”
docker:
- image: cimg/node:<< parameters.image >>

commands:
gatsby-build:
steps:
- checkout
- restore_cache:
keys:
- v1-npm-deps-{{ checksum “package-lock.json” }}
- run:
name: Install Dependencies
command: npm install
- save_cache:
key: v1-npm-deps-{{ checksum “package-lock.json” }}
paths:
- ./node_modules
- run:
name: Gatsby Build
command: npm run build

workflows:
version: 2
build-deploy:
jobs:
- build:
filters:
branches:
ignore:
- master
- release:
filters:
branches:
only:
- master

jobs:
build:
executor: node
working_directory: ~/Portfolio
steps:
- gatsby-build
release:
executor: node
working_directory: ~/Porfolio
steps:
- gatsby-build

Error: Since no service is running

gatsby build

info Starting to fetch data from Strapi - http://localhost:1337/about with params {"_limit":1000}
error Failed to fetch data from Strapi connect ECONNREFUSED 127.0.0.1:1337

Error: connect ECONNREFUSED 127.0.0.1:1337

I’m guessing I’m not the first to ask this question but my googling was not successfull enough to help me get past this error. I’ve run separate jobs on backend/frontend before but never beeing reliant on the backend running while the frontend was building

Hi @indiehjaerta ,

If i understand you correctly, you would like to:

  1. run Strapi application (the “backend”) in the background
  2. run Gatsby build (the “frontend”) which needs to connect to the Strapi application on http://127.0.0.1:1337

If you, you may like to take a look at the background option when running the Strapi application as a step in of the build job?

A sample reference here shows how we can run a server in the background while running a client that interacts with the server.

I believe this is perhaps identical to what you are trying to achieve?

Thank you very much, I got this answer from support and forgot to update this thread but it might help someone else that will struggle with this like me, don’t know how I found the background flag before but it was exactly what I was looking for.

Thanks again.

1 Like