Skip to content

Commit

Permalink
Deploy hopefully?
Browse files Browse the repository at this point in the history
  • Loading branch information
NickMous committed Aug 22, 2024
1 parent 5c8b1c9 commit 436ca58
Showing 1 changed file with 39 additions and 75 deletions.
114 changes: 39 additions & 75 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,93 +14,57 @@ jobs:
runs-on: ubuntu-latest

services:
mariadb:
image: mariadb:10.11
env:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: test
MYSQL_USER: test_user
MYSQL_PASSWORD: test_password
docker:
image: docker
options: --privileged
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=3

steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
- name: Checkout code
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
php-version: "8.3"
- uses: actions/checkout@v3
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Composer Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Install NPM Dependencies
run: npm install
- name: Run build
run: npm run build
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Create Database
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Copy password file
run: cp database/password.txt.example database/password.txt
- name: Copy .env file
run: cp .env.example .env
- name: Set app key
run: sed -i "s|APP_KEY=|APP_KEY=base64:$(openssl rand -base64 32)|" .env
- name: Set up Docker Compose
run: |
mkdir -p database
touch database/database.sqlite
- name: Execute tests (Unit and Feature tests) via Pest
env:
DB_CONNECTION: mariadb
DB_DATABASE: test
DB_USERNAME: test_user
DB_PASSWORD: test_password
run: vendor/bin/pest
docker compose -f compose.testing.yaml up -d
- name: Run tests
run: |
docker compose -f compose.testing.yaml --env-file .env exec server-testing ./vendor/bin/pest tests
- name: Tear down Docker Compose
run: |
docker compose -f compose.testing.yaml down
deploy:
needs: laravel-tests

runs-on: ubuntu-latest

steps:
- name: Activate maintenance mode 🛠️
uses: appleboy/ssh-action@master
- name: Checkout code
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.SSHPORT }}
script: |
cd ${{ env.PUBLIC_PATH }}
(php artisan down --secret="bypass-nick" --refresh="15") || true
- name: Deploy code to production 🚀
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.SSHPORT }}
script: |
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
cd ${{ env.PUBLIC_PATH }}
git pull
composer install --optimize-autoloader --no-dev --no-interaction --prefer-dist
php artisan clear-compiled
npm ci
php artisan migrate --force
npm run build
php artisan optimize
- name: Deactivate maintenance mode 🛠️
uses: appleboy/ssh-action@master
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.SSHPORT }}
script: |
cd ${{ env.PUBLIC_PATH }}
php artisan up
platform: linux/amd64,linux/arm64
push: true
target: prod
tags: ${{ secrets.DOCKER_USERNAME }}/cyclequest:latest

0 comments on commit 436ca58

Please sign in to comment.