-
Notifications
You must be signed in to change notification settings - Fork 2
78 lines (73 loc) · 2.2 KB
/
docker-CI.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Docker CI
on:
push:
branches: [ "load" ]
pull_request:
branches: [ "load" ]
env:
IMAGE_REGISTRY: "ghcr.io"
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Lint go
run: go vet ./...
tests:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache-dependency-path: go.sum
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ github.sha }}
restore-keys: |
${{ runner.os }}-docker-
- name: Set up Docker Compose
run: sudo apt-get update && sudo apt-get install -y docker-compose
- name: Docker up for tests
run: |
cd ./cmd/microservices
docker-compose build --progress=plain --cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache
docker-compose up -d postgres migrate-service filling-service
- name: Install dependencies
run: go mod tidy
- name: Tests
run: go test ./...
deploy:
needs: tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Run commands on server
run: |
ssh -o ServerAliveInterval=30 -i ~/.ssh/id_rsa ubuntu@${{ secrets.SSH_HOST }} << EOF
echo 'Connected successfully!'
uname -a
pwd
cd ./2024_2_TeamOn_Patreon
sudo git fetch origin
sudo git checkout load
sudo git pull origin load
cd ./cmd/microservices
sudo docker system prune
sudo docker volume rm $(docker volume ls -q) -f
sudo docker-compose down
sudo docker-compose up -d --build
EOF