V
V
vaflya2020-01-11 14:13:55
GitHub
vaflya, 2020-01-11 14:13:55

How to do github CI/CD on VPS for node.js?

Good afternoon! I'm trying to make ci/cd for github. I googled articles, there are very few sensible ones, and some are already outdated and do not work. Stuck in deploy on VPS.
How it is implemented now:
1) Written .github/workflows/push.yaml

# Создаем тригер когда кто-то пушит код в репозиторий
on: push
name: npm build, lint, test and publish

# Создаем задачи для сборки проекта и запуска на ubuntu-latest.
# Каждая задача будет запущенна в новой копии приложения на виртуальном сервереt..
jobs:
  build-and-publish:
    name: build and publish
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
        with:
          node-version: '10.x'
      - run: npm install
      - run: npm test

        # Создаем Docker образ
      - name: Publish to Docker Repository
        uses: elgohr/[email protected]
        with:
          name: vaflya/project
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          run: docker build -t back .

2) github installs dependencies and runs tests
3) creates a docker container
Dockerfile
FROM node
WORKDIR /
COPY . .
RUN npm install
EXPOSE 3000
ENTRYPOINT ["npm", "start"]

4) Push to docker hub
and then stop. How can I know from the VPS side that a new container has been created and deploy it to the VPS?
And do I need to use docker in my case? Given that I only use docker-compose

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
de1m, 2020-01-12
@de1m

You are cooking the cat wrong.
Point three must be done passively, that is, enable integration with github in docker hub and then you can create "Automated build". Each push will create an image.
The script below can check if the image exists:

function docker_tag_exists() {
    curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 > /dev/null
}

if docker_tag_exists library/nginx 1.7.5; then
    echo exist
else 
    echo not exists
fi

D
Dmitry, 2020-01-11
@q2digger

To do this, they came up with a special service - watchtower , roll out this container for yourself, it monitors the updates of the containers deployed on the host and updates them if necessary.
https://github.com/containrrr/watchtower

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question