feat: ci for all pushes, deploy with ssh key, local compose with build
This commit is contained in:
+9
-11
@@ -1,27 +1,25 @@
|
|||||||
name: ci
|
name: CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches-ignore:
|
||||||
- dev
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
- master
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v6
|
|
||||||
- name: Node setup
|
- uses: actions/setup-node@v4
|
||||||
uses: actions/setup-node@v6
|
|
||||||
with:
|
with:
|
||||||
node-version: "25"
|
node-version: "25"
|
||||||
|
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: npm install
|
run: npm install
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
|
|||||||
@@ -13,24 +13,30 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup SSH
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
|
||||||
- name: Install Ansible
|
- name: Install Ansible
|
||||||
run: apt update && apt install -y ansible
|
run: apt update && apt install -y ansible
|
||||||
|
|
||||||
- name: Login to registry
|
- name: Login to registry
|
||||||
run: echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login $REGISTRY -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
run: echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login $REGISTRY -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||||
|
|
||||||
- name: Build and push image
|
- name: Build and push
|
||||||
run: |
|
run: |
|
||||||
IMAGE=$REGISTRY/hellreign/frontend
|
IMAGE=$REGISTRY/hellreign/frontend
|
||||||
docker build -f dockerfile -t $IMAGE:dev -t $IMAGE:${{ gitea.sha }} .
|
docker build -f dockerfile -t $IMAGE:dev -t $IMAGE:latest .
|
||||||
docker push $IMAGE:dev
|
docker push $IMAGE:dev
|
||||||
docker push $IMAGE:${{ gitea.sha }}
|
docker push $IMAGE:latest
|
||||||
|
|
||||||
- name: Deploy via Ansible
|
- name: Deploy
|
||||||
run: |
|
run: |
|
||||||
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD }}" > .vault_pass
|
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD }}" > .vault_pass
|
||||||
ansible-playbook -i infra/ansible/inventory/hosts.yml infra/ansible/playbook.yml \
|
ansible-playbook -i infra/ansible/inventory/hosts.yml infra/ansible/playbook.yml \
|
||||||
--vault-password-file .vault_pass \
|
--vault-password-file .vault_pass \
|
||||||
-e registry=$REGISTRY \
|
-e registry=$REGISTRY \
|
||||||
-e tag=${{ gitea.sha }}
|
-e tag=latest
|
||||||
rm .vault_pass
|
rm .vault_pass
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
app:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: dockerfile
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
@@ -4,7 +4,3 @@ all:
|
|||||||
ansible_host: <SERVER_IP>
|
ansible_host: <SERVER_IP>
|
||||||
ansible_user: root
|
ansible_user: root
|
||||||
ansible_port: 22
|
ansible_port: 22
|
||||||
vars:
|
|
||||||
registry: gitea.d3m0k1d.ru
|
|
||||||
registry_user: <REGISTRY_USER>
|
|
||||||
registry_password: <REGISTRY_PASSWORD>
|
|
||||||
|
|||||||
@@ -15,10 +15,6 @@
|
|||||||
src: "{{ playbook_dir }}/../docker-compose.yml"
|
src: "{{ playbook_dir }}/../docker-compose.yml"
|
||||||
dest: "{{ deploy_path }}/docker-compose.yml"
|
dest: "{{ deploy_path }}/docker-compose.yml"
|
||||||
|
|
||||||
- name: Login to registry
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: echo "{{ registry_password }}" | docker login "{{ registry }}" -u "{{ registry_user }}" --password-stdin
|
|
||||||
|
|
||||||
- name: Pull images
|
- name: Pull images
|
||||||
ansible.builtin.shell:
|
ansible.builtin.shell:
|
||||||
cmd: docker compose pull
|
cmd: docker compose pull
|
||||||
@@ -27,7 +23,7 @@
|
|||||||
REGISTRY: "{{ registry }}"
|
REGISTRY: "{{ registry }}"
|
||||||
TAG: "{{ tag }}"
|
TAG: "{{ tag }}"
|
||||||
|
|
||||||
- name: Restart services
|
- name: Start services
|
||||||
ansible.builtin.shell:
|
ansible.builtin.shell:
|
||||||
cmd: docker compose up -d --remove-orphans
|
cmd: docker compose up -d --remove-orphans
|
||||||
chdir: "{{ deploy_path }}"
|
chdir: "{{ deploy_path }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user