From 9e596456165b047b92b9672b11dc58a510d616cb Mon Sep 17 00:00:00 2001 From: Magehawks Date: Fri, 8 Mar 2024 11:04:13 +0100 Subject: [PATCH] test gitlabci --- .github/workflows/ci-cd.yml | 5 +-- .github/workflows/ssh_deploy.yml | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ssh_deploy.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index a92a3b4..55149c9 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -56,7 +56,4 @@ jobs: push: true tags: user/my-app:latest context: . - file: ./Dockerfile - - - + file: ./Dockerfile \ No newline at end of file diff --git a/.github/workflows/ssh_deploy.yml b/.github/workflows/ssh_deploy.yml new file mode 100644 index 0000000..baffd85 --- /dev/null +++ b/.github/workflows/ssh_deploy.yml @@ -0,0 +1,66 @@ +# Based on this tutorial: https://github.com/marketplace/actions/ssh-deploy +name: SSH Deploy +on: + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v1 + # Install PHP + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + coverage: none + tools: composer:v2 + extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, dom, filter, gd, iconv, json, mbstring, pdo + env: + update: true + - name: Check PHP Version + run: php -v + # Install backend dependencies (Composer) + - name: Validate composer.json and composer.lock + run: composer validate + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache composer dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + - name: Install Composer dependencies + run: composer install + # Prepare .env file for production + - name: Make production envfile + uses: SpicyPizza/create-envfile@v1 + with: + envkey_APP_ENV: prod + envkey_APP_DEBUG: false + envkey_APP_SECRET: ${{ secrets.APP_SECRET }} + file_name: .env + # Copying files and artifacts via SSH + - name: Copying files to server + uses: appleboy/scp-action@master + with: + host: ${{ secrets.REMOTE_HOST }} + username: ${{ secrets.REMOTE_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + passphrase: '' + rm: true + source: "./" + target: ${{ secrets.REMOTE_TARGET }} + # Run commands on production + - name: Executing remote ssh commands + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.REMOTE_HOST }} + username: ${{ secrets.REMOTE_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + passphrase: '' + script: | + rsync -a --exclude={'var','temp'} --delete ${{ secrets.REMOTE_TARGET }} ${{ secrets.REMOTE_TARGET_DEPLOY }} + cd ${{ secrets.REMOTE_TARGET }} && php8.2 bin/console cache:clear \ No newline at end of file