Skip to content

Commit c499928

Browse files
author
Kroner
committed
add ansible playbook | fix ci/cd
1 parent 823f8f2 commit c499928

File tree

4 files changed

+98
-3
lines changed

4 files changed

+98
-3
lines changed

.github/workflows/main.yml

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ on:
44
push:
55
branches:
66
- main # Запускать пайплайн при пуше в ветку main
7-
- v0.8
87

98
jobs:
10-
test:
9+
tests:
1110
runs-on: ubuntu-latest
1211
steps:
1312
- name: Checkout code
@@ -27,4 +26,40 @@ jobs:
2726
- name: Run tests
2827
run: |
2928
cd go/
30-
go test -v
29+
go test -v
30+
31+
deploy:
32+
runs-on: ubuntu-latest
33+
needs: tests
34+
env:
35+
REMOTE_DIR: "/tmp"
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v3
39+
40+
- name: executing remote ssh commands using password
41+
uses: appleboy/ssh-action@v1
42+
with:
43+
host: ${{ secrets.SERVER_DNS }}
44+
username: deployer
45+
key: ${{ secrets.SSH_PRIVATE_KEY }}
46+
script: |
47+
sudo apt update && sudo apt install -y ansible
48+
scp -r ./deploy-docker.yml ./ansible.cfg deployer@${{ secrets.SERVER_DNS }}:${{ env.REMOTE_DIR }}/
49+
ANSIBLE_CONFIG=${{ env.REMOTE_DIR }}/ansible.cfg ansible-playbook ${{ env.REMOTE_DIR }}/deploy-docker.yml
50+
51+
52+
53+
54+
55+
# Хочу запустить ansible-playbook
56+
# Для этого надо:
57+
# 0. Подключиться к серверу - uses: appleboy/ssh-action@v1 - готово
58+
# 1. установить/проверить ansible на сервере - внутри пункта 0 - готово
59+
# 2. Передать плейбук и его конфиг на сервер - через scp или новый шаг?
60+
# 3. Запустить плейбук -
61+
#
62+
#
63+
#
64+
#
65+
#

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.log
2+
*.ip

ansible.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[defaults]
2+
stdout_callback = log_plays

deploy-docker.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
- name: Deploy GoServ via Docker Compose
3+
become: yes
4+
5+
vars:
6+
docker_key_dir: /usr/share/keyrings
7+
repo_url: "https://github.com/Kron-x/GoServ.git"
8+
app_dir: "{{ ansible_user_dir }}/server" # файл с рабочим серавком
9+
10+
tasks:
11+
- name: Ensure keyring directory exists
12+
file:
13+
path: "{{ docker_key_dir }}"
14+
state: directory
15+
mode: 0755
16+
17+
- name: Download Docker GPG key (proper way)
18+
ansible.builtin.get_url:
19+
url: "https://download.docker.com/linux/ubuntu/gpg"
20+
dest: "{{ docker_key_dir }}/docker-archive-keyring.gpg"
21+
mode: "0644"
22+
23+
- name: Add Docker repository (secure way)
24+
ansible.builtin.apt_repository:
25+
repo: "deb [arch=amd64 signed-by={{ docker_key_dir }}/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu noble stable"
26+
state: present
27+
filename: "docker"
28+
29+
- name: Install Docker & Docker Compose (v2)
30+
apt:
31+
name:
32+
- docker-ce
33+
- docker-ce-cli
34+
- containerd.io
35+
- docker-compose-plugin
36+
state: present
37+
38+
- name: Ensure Docker is running
39+
service:
40+
name: docker
41+
state: started
42+
enabled: yes
43+
44+
- name: Clone repository
45+
git:
46+
repo: "{{ repo_url }}"
47+
dest: "{{ app_dir }}"
48+
49+
- name: Run Docker Compose
50+
command: docker compose up -d
51+
args:
52+
chdir: "{{ app_dir }}"
53+
54+
- name: Ensure Docker Compose restarts on reboot
55+
systemd:
56+
name: docker
57+
enabled: yes

0 commit comments

Comments
 (0)