File tree Expand file tree Collapse file tree 2 files changed +69
-27
lines changed Expand file tree Collapse file tree 2 files changed +69
-27
lines changed Original file line number Diff line number Diff line change 1
- name : CI/CD
1
+ name : CI
2
2
3
3
on :
4
4
push :
9
9
- main
10
10
11
11
jobs :
12
- build :
13
- name : Build and Push to GHCR
14
- runs-on : ubuntu-latest
15
-
16
- needs : test
17
- steps :
18
- - name : Check out code
19
- uses : actions/checkout@v2
20
-
21
- - name : Set up Go
22
- uses : actions/setup-go@v2
23
- with :
24
- go-version : ' 1.23'
25
-
26
- - name : Build Docker Image
27
- run : docker build --build-arg VERSION=$(git describe --tags --always) --build-arg BUILDTIME="$(date -R)" . -f build/Dockerfile -t ghcr.io/${{ github.repository }}:latest
28
-
29
- - name : Log in to GitHub Container Registry
30
- uses : docker/login-action@v2
31
- with :
32
- registry : ghcr.io
33
- username : ${{ github.actor }}
34
- password : ${{ secrets.GITHUB_TOKEN }}
35
-
36
- - name : Push Docker Image
37
- run : docker push ghcr.io/${{ github.repository }}:latest
38
12
check-dependencies :
39
13
name : Check dependencies with nancy
40
14
runs-on : ubuntu-latest
Original file line number Diff line number Diff line change
1
+ name : CD
2
+
3
+ on :
4
+ push :
5
+ # branches:
6
+ # - main
7
+ pull_request :
8
+ # branches:
9
+ # - main
10
+ workflow_dispatch : # Позволяет запустить workflow вручную через интерфейс GitHub
11
+
12
+ jobs :
13
+ build :
14
+ name : Build and Push to GHCR
15
+ runs-on : ubuntu-latest
16
+
17
+ # needs: test
18
+ steps :
19
+ - name : Check out code
20
+ uses : actions/checkout@v2
21
+
22
+ - name : Set up Go
23
+ uses : actions/setup-go@v2
24
+ with :
25
+ go-version : ' 1.23'
26
+
27
+ - name : Build Docker Image
28
+ run : |
29
+ git fetch --unshallow --tags
30
+ BUILDTIME=$(date -R)
31
+ docker build --build-arg VERSION=$(git describe --tags --always) --build-arg BUILDTIME='$BUILDTIME' . -f build/Dockerfile -t ghcr.io/${{ github.repository }}:latest
32
+
33
+ - name : Log in to GitHub Container Registry
34
+ uses : docker/login-action@v2
35
+ with :
36
+ registry : ghcr.io
37
+ username : ${{ github.actor }}
38
+ password : ${{ secrets.GITHUB_TOKEN }}
39
+
40
+ - name : Push Docker Image
41
+ run : docker push ghcr.io/${{ github.repository }}:latest
42
+
43
+ deploy :
44
+ name : Deploy to Staging
45
+ runs-on : ubuntu-latest
46
+ needs : build
47
+ # if: github.event_name == 'workflow_dispatch'
48
+ steps :
49
+ - name : Install SSH and other dependencies
50
+ run : |
51
+ sudo apt-get update
52
+ sudo apt-get install -y openssh-client
53
+
54
+ - name : Set up SSH
55
+ run : |
56
+ mkdir -p /root/.ssh
57
+ echo "${{ secrets.STAGE_SSH_KEY }}" > /root/.ssh/id_rsa
58
+ chmod 600 /root/.ssh/id_rsa
59
+ ssh-keyscan -H ctf01d.ru >> /root/.ssh/known_hosts
60
+
61
+ - name : Deploy Docker Compose to Staging
62
+ run : |
63
+ scp build/docker-compose.staging.yml root@ctf01d.ru:/root/ctf01d-training-platform/build
64
+ ssh root@ctf01d.ru "docker login ghcr.io -u '${{ secrets.GHCR_USERNAME }}' -p '${{ secrets.GHCR_TOKEN }}' && docker compose pull && docker compose stop && docker compose up -d"
65
+
66
+ environment :
67
+ name : staging
68
+ url : http://staging.example.com
You can’t perform that action at this time.
0 commit comments