Giter Site home page Giter Site logo

europemap's Introduction

Deployment guide

This is a guide to deploy a react vite app to Digital Ocean using Docker and Github Actions.

Steps

  1. Create a droplet on Digital Ocean
  2. Create a new project on Github
  3. Create a new repository on Github
  4. Clone the repository to your local machine
  5. Create a new react vite app
  6. Push the app to Github
  7. Create a Dockerfile with the following steps (see template below):
  • Use the official Node image as a base image
  • Copy package.json and package-lock.json to the container
  • Install dependencies
  • Copy the rest of the application code to the container
  • Build the Vite app (to get the dist folder)
  • Install pm2 and serve globally to run the app
  • Expose the port that your app is running on in order to access it from outside the container
  • Command to run your app using pm2 and serve on port 5000 (for production as --spa (single page application))
  1. Create a docker-compose.yml file
  2. Create a Github Actions workflow
  • Use the template below
  1. Setup a Docker Hub account if you dont have one
  2. Create a new access token on docker hub
  3. Add 2 secrets to your Github repository
  • DOCKERHUB_USERNAME
  • DOCKERHUB_TOKEN
  1. Push the changes to Github
  2. Check the Github Actions workflow
  3. Check the Docker Hub repository
  4. Login to the Digital Ocean droplet and pull the image from Docker Hub
  • docker pull your-docker-username/your-app-name:latest and
  • docker run -p 3000:3000 your-docker-username/your-app-name:latest
  1. Check the app in the browser

debugging

  • On droplet: docker ps -a - list all containers on the system
  • On droplet: docker logs <container_id> - show logs for container with id <container_id>
  • Building the image: docker build -t <image name> . from the root of the project where the Dockerfile is located
  • Running container in a way that it will stay open: docker run -p 3000:3000 europe tail -f /dev/null
  • Entering the container: docker exec -it <container_id> /bin/sh
  • Exiting the container: exit

Docker file

The docker file will be used to build the image for the app. The image will be used to run the app in a container.

# Use the official Node image as a base image
FROM node:14-alpine

# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json to the container
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code to the container
COPY . .

# Build the Vite app
RUN npm run build

# Install 'pm2' and 'serve' globally (if not already installed)
RUN npm install -g serve
# RUN npm install -g pm2

# Expose the port that your app is running on
EXPOSE 3000

# CMD ["pm2-runtime", "serve", "dist", "3000", "--spa"]
CMD ["serve", "dist", "-l", "3000"]

Github workflow file

The Github workflow file will be used to build the image and push it to Docker Hub.

name: React Build and Deploy to Docker Hub

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - 
        name: Checkout repository
        uses: actions/checkout@v2
      - 
        name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
      -
        name: Build and push
        uses: docker/build-push-action@v4
        with:
          context: .
          file: ./Dockerfile
          push: true
          tags: ${{ secrets.DOCKERHUB_USERNAME }}/europemap:latest

europemap's People

Contributors

thomas-hartmann avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.