-
Notifications
You must be signed in to change notification settings - Fork 1
38 lines (36 loc) · 1.5 KB
/
cicd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build-and-push-to-registry:
runs-on: ubuntu-latest
services: # use docker services for building and pushing compose file inside the repo
docker:
image: docker:latest
options: --privileged
steps:
- uses: actions/checkout@v4 # use this is an action to check the repo codes
- name: Login to DockerHub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin docker.hoopoe.app
- name: Build and Push
run: | # 1 - build services | 2 - push services to the custom registry hosted on docker.hoopoe.app
sudo docker compose -f "docker-compose.yml" build
sudo docker compose -f "docker-compose.yml" push
pull-from-registry-on-server:
runs-on: ubuntu-latest
needs: build-and-push-to-registry
steps:
- name: Deploy to server
uses: appleboy/ssh-action@master # use this is an action to login into the ssh
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_PASSWORD }}
port: 22
script: | # 1 - pull services from the custom registry (each image in dockercompose file prefixed with registry name) | 2 - up all the services
cd /root/hoopoe
sudo docker compose -f "docker-compose.yml" pull
sudo docker compose -f "docker-compose.yml" up -d