Skip to content

Commit 271b380

Browse files
committed
ci(deps): 🚀 add delivery by button
1 parent 7687457 commit 271b380

File tree

2 files changed

+69
-27
lines changed

2 files changed

+69
-27
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI/CD
1+
name: CI
22

33
on:
44
push:
@@ -9,32 +9,6 @@ on:
99
- main
1010

1111
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
3812
check-dependencies:
3913
name: Check dependencies with nancy
4014
runs-on: ubuntu-latest

.github/workflows/cd.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 ~/.ssh
57+
echo "${{ secrets.STAGE_SSH_KEY }}" > ~/.ssh/id_rsa
58+
chmod 600 ~/.ssh/id_rsa
59+
ssh-keyscan -H ctf01d.ru >> ~/.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

0 commit comments

Comments
 (0)