feature ci/cd test 0.0046
This commit is contained in:
@@ -3,15 +3,42 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: node-ansible
|
||||||
|
steps:
|
||||||
|
- name: Setup SSH key
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > /tmp/id_rsa
|
||||||
|
chmod 600 /tmp/id_rsa
|
||||||
|
|
||||||
|
- name: Install Ansible collection
|
||||||
|
run: ansible-galaxy collection install community.docker
|
||||||
|
|
||||||
|
- name: Create inventory
|
||||||
|
run: echo "${{ secrets.INVENTORY }}" > inventory.ini
|
||||||
|
|
||||||
|
- name: Create secrets.yml
|
||||||
|
run: echo "${{ secrets.SECRETS }}" > secrets.yml
|
||||||
|
|
||||||
|
- name: Create .env file
|
||||||
|
run: echo "${{ secrets.WEDDING_SITE_ENV }}" > .env
|
||||||
|
|
||||||
|
- name: Run Ansible playbook
|
||||||
|
run: ansible-playbook -i inventory.ini deploy.yml -e @secrets.yml
|
||||||
|
env:
|
||||||
|
ANSIBLE_PRIVATE_KEY_FILE: /tmp/id_rsa
|
||||||
|
|
||||||
build:
|
build:
|
||||||
runs-on: node-docker
|
runs-on: node-docker
|
||||||
|
needs: deploy
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Create .env file
|
- name: Create .env file
|
||||||
run: |
|
run: echo "${{ secrets.WEDDING_SITE_ENV }}" > .env
|
||||||
echo "${{ secrets.WEDDING_SITE_ENV }}" > .env
|
|
||||||
- name: Build image
|
- name: Build image
|
||||||
run: docker build -t back:latest -f docker/dockerfile .
|
run: docker build -t back:latest -f docker/dockerfile .
|
||||||
- name: Start docker-compose
|
- name: Start docker-compose
|
||||||
run: docker compose --env-file .env -f docker/docker-compose.yaml up -d
|
run: docker compose --env-file .env -f docker/docker-compose.yaml up -d
|
||||||
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -22,6 +22,7 @@ hint.py
|
|||||||
|
|
||||||
#env
|
#env
|
||||||
*.env
|
*.env
|
||||||
|
secrets.yml
|
||||||
#db
|
#db
|
||||||
*.db
|
*.db
|
||||||
versions/
|
versions/
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
- hosts: servers
|
- hosts: servers
|
||||||
become: yes
|
become: yes
|
||||||
|
vars:
|
||||||
|
env_file: .env
|
||||||
tasks:
|
tasks:
|
||||||
- name: Install Docker
|
- name: Install Docker
|
||||||
shell: curl -fsSL https://get.docker.com | sh
|
apt:
|
||||||
args:
|
name: docker-compose
|
||||||
creates: /usr/bin/docker
|
state: present
|
||||||
|
update_cache: yes
|
||||||
|
- name: Copy .env to remote
|
||||||
|
copy:
|
||||||
|
src: "{{ env_file }}"
|
||||||
|
dest: /opt/infra/.env
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0600'
|
||||||
|
|
||||||
- name: Install git
|
- name: Install git
|
||||||
apt:
|
apt:
|
||||||
@@ -14,10 +24,11 @@
|
|||||||
|
|
||||||
- name: Clone repo
|
- name: Clone repo
|
||||||
git:
|
git:
|
||||||
repo: ${GITEA_INSTANCE_URL} //как то передавать переменные
|
repo: "{{ gitea_instance_url }}"
|
||||||
dest: /opt/infra
|
dest: /opt/infra
|
||||||
|
|
||||||
- name: Start docker compose
|
- name: Start docker compose via module
|
||||||
shell: docker compose up -d
|
community.docker.docker_compose:
|
||||||
args:
|
project_src: /opt/infra
|
||||||
chdir: /opt/infra
|
state: present
|
||||||
|
restarted: true
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
ansible-playbook -i inventory.ini deploy.yml -e "target_host=$HOST"
|
|
||||||
GITEA_INSTANCE_URL="..."
|
|
||||||
HOST="..."
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
[servers]
|
|
||||||
myserver ansible_user=root
|
|
||||||
2
ansible/inventory_example
Normal file
2
ansible/inventory_example
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[servers]
|
||||||
|
myserver host=... ansible_user=...
|
||||||
1
ansible/secrets_example
Normal file
1
ansible/secrets_example
Normal file
@@ -0,0 +1 @@
|
|||||||
|
gitea_instance_url: ...
|
||||||
12
docker/gitea_runners/node-ansible.yaml
Normal file
12
docker/gitea_runners/node-ansible.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
services:
|
||||||
|
runner:
|
||||||
|
image: gitea/act_runner:latest
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- ./data/act_runner:/data
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
environment:
|
||||||
|
- GITEA_INSTANCE_URL=${GITEA_INSTANCE_URL}
|
||||||
|
- GITEA_RUNNER_REGISTRATION_TOKEN=${TOKEN}
|
||||||
|
- GITEA_RUNNER_NAME=docker-runner
|
||||||
|
- GITEA_RUNNER_LABELS=node-ansible:docker://homyakspace/wedding-ansible:${TAG}
|
||||||
@@ -9,4 +9,4 @@ services:
|
|||||||
- GITEA_INSTANCE_URL=${GITEA_INSTANCE_URL}
|
- GITEA_INSTANCE_URL=${GITEA_INSTANCE_URL}
|
||||||
- GITEA_RUNNER_REGISTRATION_TOKEN=${TOKEN}
|
- GITEA_RUNNER_REGISTRATION_TOKEN=${TOKEN}
|
||||||
- GITEA_RUNNER_NAME=docker-runner
|
- GITEA_RUNNER_NAME=docker-runner
|
||||||
- GITEA_RUNNER_LABELS=node-docker:docker://homyakspace/wedding:${TAG}, node-ansible:docker://homyakspace/wedding-ansible:${TAG}
|
- GITEA_RUNNER_LABELS=node-docker:docker://homyakspace/wedding:${TAG}
|
||||||
Reference in New Issue
Block a user