https://github.com/hirurg-lybitel/docker-server-with-github-actions
Deploying a simple server on a remote machine
https://github.com/hirurg-lybitel/docker-server-with-github-actions
docker docker-compose esbuild github-actions node pm2 ssh workflows yarn3
Last synced: 3 months ago
JSON representation
Deploying a simple server on a remote machine
- Host: GitHub
- URL: https://github.com/hirurg-lybitel/docker-server-with-github-actions
- Owner: hirurg-lybitel
- License: mit
- Created: 2023-10-09T12:22:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-10T17:37:39.000Z (over 2 years ago)
- Last Synced: 2023-10-11T00:20:58.303Z (over 2 years ago)
- Topics: docker, docker-compose, esbuild, github-actions, node, pm2, ssh, workflows, yarn3
- Language: JavaScript
- Homepage: http://213.184.249.125:60103
- Size: 13.7 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Deploy server with github actions
This example illustrates how to set up automatic build and deployment of a docker image on your remote server by [GitHub Acions]([url](https://docs.github.com/en/actions)).
View the result on the [demo server](http://213.184.249.125:60103).
There're three main points here:
1. Node App
2. GitHub-actions
3. Remote machine
## Node App
There is a few ways to run app locally:
- by node
```
yarn launch
```
- by pm2
```
yarn pm2:start
```
- by docker
```
docker compose up
```
## GitHub Actions
**Here you need to set several mandatory secrets for your repository (_Settings -> Secrets and variables -> Actions_):**
- **DOCKER_*** - your Docker Hub credentials;
- **DEPLOY_*** - SSH data for connection to your remote machine.

**After push cahnges to github on **main** branch go to Actions tab of your repository:**

**Two tasks will appear here which will:**
1. check your code
2. build a docker image
3. upload it to GitHub Container Registry (GitHub alternative to Docker)
4. connect to your remote server
5. deploy the built image on it
## Remote machine*
*change path _workspace/Yuri/test_ in [docker-deploy.yml](https://github.com/hirurg-lybitel/docker-server-with-github-actions/blob/main/.github/workflows/docker-deploy.yml) to your path.
In addition to setting up ssh and port forwarding, several files are needed here:
- .env
- docker-compose.run.yml
- run_container.sh

### .env
See [.env.sample](https://github.com/hirurg-lybitel/docker-server-with-github-actions/blob/main/.env.sample) and enter your data.
### docker-compose.run.yml
Docker compose file for creating and running container:
```yml
version: "3.8"
services:
server:
image: ghcr.io/hirurg-lybitel/docker-server-with-github-actions:main
build:
context: .
dockerfile: Dockerfile
target: server
args:
- PM2_PUBLIC_KEY=${PM2_PUBLIC_KEY}
- PM2_SECRET_KEY=${PM2_SECRET_KEY}
container_name: simple_server
ports:
- "${PORT}:${PORT}"
env_file:
- ./.env
```
### run_container.sh
Bash script for calling docker compose:
```bash
docker compose -f docker-compose.run.yml --env-file .env up -d
```
## PM2 monitoring
After launching project locally [by pm2](#node-app) or deploying it on remote server you will able to monitor your server in [PM2 dashboard](https://id.keymetrics.io/api/oauth/register):
