🍝 Deliveroo Clone - NextJS, Strapi, GraphQL, Stripe, React Context (Part 7/7 - Deploy)

This tutorial is a part of the Β« NextJS, Strapi, GraphQL, Stripe Deliveroo clone (Part 7/7 - Deploy) Β»:

Table of contents

Note: the source code is available on GitHub: https://github.com/ryanbelke/strapi-next

πŸš€ Bonus: deploy

At this point, we only need to deploy our API and our web app.
Strpi can be hosted on any major provider offering node deployments (AWS, Heroku, DO). Read further about deployment of Strapi here:
https://strapi.io/documentation/3.x.x/guides/deployment.html

note: for deployment you will need to change your URLs and connection strings from the default localhost:1337 we were using in the tutorial to actual URL your deploying to

Backend

Init a git project and commit your files:

rm package-lock.json # May involved errors if not removed  
git init  
git add .  
git commit -am "Initial commit"  

Make sure the Heroku CLI is installed on your computer and deploy:

heroku create  
heroku addons:create mongolab:sandbox --as DATABASE  
git push heroku master  

Heroku deploy

Visit the URLΒ provided by Heroku and keep it for the next step.

Note: you will have to redefine your permissions rules from the interface. This workflow will be improved in the near future.

Next Deployment

You can host next projects anywhere a node project can be deployed as it is just a node pacakage. For this tutorial we will deploy to NOW, a serverless deployment provider:
https://zeit.co/now

Init a git project and commit your files:

First install the NOW command line:

npm i -g now  

Follow the instructions to confirm your email

Add the following Dockerfile which will:

  • Install all the dependencies
  • Build the application for production
  • Remove non-production dependencies
  • Create a new lighter Docker image to reduce boot time
  • Pull built files and production dependencies from previous steps
  • Expose the port 300 and run the application

Create the Dockerfile at the root of the project:
touch Dockerfile

Add:

FROM mhart/alpine-node:10 as base  
WORKDIR /usr/src  
COPY package.json yarn.lock /usr/src/  
RUN yarn install  
COPY . .  
RUN yarn build && yarn --production

FROM mhart/alpine-node:base-10  
WORKDIR /usr/src  
ENV NODE_ENV="production"  
COPY --from=base /usr/src .  
EXPOSE 3000  
CMD ["node", "./node_modules/.bin/next", "start"]  

Then:
create a now.json file at the root

touch now.json  

Contents:

{
  "type": "docker",
  "public": true,
  "features": {
    "cloud": "v2"
  }
}

Run command now for deployment

Conclusion

Huge congrats, you successfully achieved this tutorial. I hope you enjoyed it!

The source code is available on GitHub: https://github.com/ryanbelke/strapi-next.

Still hungry?

Feel free to add additional features, adapt this projects to your own needs and give your feedback in the comments section.

Share your meal!

You enjoyed this tutorial? Share it around you!