Skip to content

Deploy to docker hub #43

Deploy to docker hub

Deploy to docker hub #43

Workflow file for this run

name: Node.js CI
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Build Docker image
env:
POSTGRES_USER: ${{ secrets.DB_USER }}
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }}
POSTGRES_DATABASE: ${{ secrets.DEV_DATABASE }}
run: |
echo "POSTGRES_USER=${POSTGRES_USER}"
docker compose build -t todo
- name: Run Docker Compose file
env:
POSTGRES_USER: ${{ secrets.DB_USER }}
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }}
POSTGRES_DATABASE: ${{ secrets.DEV_DATABASE }}
run: |
docker compose up -d && sleep 20
docker compose ps
docker compose logs db
docker compose logs app
- name: Run unit tests
env:
POSTGRES_USER: ${{ secrets.DB_USER }}
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }}
POSTGRES_DATABASE: ${{ secrets.DEV_DATABASE }}
run: docker compose exec app npm test
- name: Run integration tests
uses: cypress-io/github-action@v6
with:
start: npm start
# env:
# POSTGRES_USER: ${{ secrets.DB_USER }}
# POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }}
# POSTGRES_DATABASE: ${{ secrets.DEV_DATABASE }}
# run: |
# docker compose exec app npm install cypress cypress-json-results
# docker compose exec app npx cypress run
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Run application with database
env:
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
run: |
docker run -d \
-e DB_PASSWORD=$DB_PASSWORD \
--name todo \
todo
# - name: Setup SSH
# run: |
# mkdir -p ~/.ssh
# echo "${{ secrets.SERVER_SSH_KEY }}" > ~/.ssh/id_rsa
# chmod 600 ~/.ssh/id_rsa
# ssh-keyscan github.com >> ~/.ssh/known_hosts
# - name: Deploy to the server
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.SERVER_HOST }}
# username: ${{ secrets.SERVER_USER }}
# key: ${{ secrets.SERVER_SSH_KEY }}
# script: |
# docker pull todo-app:latest
# docker stop todo-app || true
# docker rm todo-app || true
# docker run -d --name todo-app -p 80:80 todo-app:latest
# debug: true
- name: Stop and remove Docker containers
run: docker compose down