Docker Image Builder #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Image Builder | |
on: | |
push: | |
branches: [ master ] | |
paths: | |
- 'nginx/**' | |
- 'mysql/**' | |
- 'deploy_manager/**' | |
- 'sshproxy/**' | |
- 'bx_installer/**' | |
- 'httpd/**' | |
- 'adminer/**' | |
- 'docker-compose.build.yml' | |
- 'docker-compose.main_proxy.yml' | |
workflow_dispatch: | |
inputs: | |
skip_build: | |
description: 'Пропустить сборку и пуш образов' | |
required: false | |
default: false | |
type: boolean | |
jobs: | |
docker-build: | |
name: Сборка и пуш образов в Github Registry Packages | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' || !github.event.inputs.skip_build | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Docker login | |
env: | |
DOCKER_USER: ${{ secrets.DOCKER_USER }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
run: | |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD ghcr.io | |
- name: Docker build | |
run: | |
docker-compose -f docker-compose.build.yml build --parallel | |
- name: Push containers | |
run: | |
docker-compose -f docker-compose.build.yml push | |
deploy: | |
name: Деплой на сервер | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
needs: [docker-build] | |
steps: | |
- name: Пул Докер образов, git pull и перезапуск сервера | |
uses: appleboy/ssh-action@v0.1.10 | |
env: | |
DEPLOY_ENV_PATH: ${{ secrets.DOCKER_ENV_PATH }} | |
NEED_DEPLOY: ${{ env.NEED_DEPLOY }} # todo сделать переключатель для деплоя | |
SSH_MAIN_USER: ${{ secrets.SSH_MAIN_USER }} | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
port: ${{ secrets.SSH_PORT }} | |
script_stop: true | |
envs: DEPLOY_ENV_PATH,NEED_DEPLOY,SSH_MAIN_USER | |
script: | | |
cd $DEPLOY_ENV_PATH | |
bash sandbox stop | |
su $SSH_MAIN_USER -c 'git reset --hard' | |
su $SSH_MAIN_USER -c 'git pull origin master' | |
bash sandbox pull_proxy | |
bash sandbox start |