Skip to content

Update docker compose #68

Update docker compose

Update docker compose #68

Workflow file for this run

name: Symfony deployment
on:
push:
branches: [ "alpha" ]
pull_request:
branches: [ "alpha" ]
permissions:
contents: read
jobs:
validate:
name: Symfony (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
# Docs: https://docs.github.com/en/actions/using-containerized-services
services:
mysql:
image: mysql:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: symfony
MYSQL_DATABASE: symfony
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
matrix:
php-versions: ['8.1']
steps:
- name: Checkout
uses: actions/checkout@v4
# Docs: https://github.com/shivammathur/setup-php
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: phpunit-bridge
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql
coverage: xdebug
# Local MySQL service in GitHub hosted environments is disabled by default.
# If you are using it instead of service containers, make sure you start it.
# - name: Start mysql service
# run: sudo systemctl start mysql.service
- name: Copy .env.dist
# run: php -r "file_exists('.env.local') || copy('.env.${{ github.ref_name }}', '.env.local');"
run: php -r "file_exists('.env.local') || copy('.env.dist', '.env.local');"
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
if: steps.composer-cache.outputs.cache-hit != 'true' # Skip if cache hit
run: composer install --no-progress --prefer-dist --optimize-autoloader
# run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Run Migration
run: |
composer require --dev symfony/orm-pack
php bin/console doctrine:schema:update --complete --force || echo "No migrations found or schema update failed"
php bin/console doctrine:migrations:migrate || echo "No migrations found or migration failed"
env:
DATABASE_URL: mysql://root:[email protected]:${{ job.services.mysql.ports['3306'] }}/symfony
# - name: Install PHPUnit
# run: simple-phpunit install
#
# - name: Run tests
# run: simple-phpunit --coverage-text
deploy:
name: Deploy image
runs-on: ubuntu-latest
needs: validate
steps:
- uses: actions/checkout@v4
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_LOGIN }}
password: ${{ secrets.DOCKER_PASSWD }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ secrets.DOCKER_REGISTRY }}/api-php:${{ github.ref_name }}
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/staging.key
chmod 600 ~/.ssh/staging.key
cat >>~/.ssh/config <<END
Host staging
HostName $SSH_HOST
User $SSH_USER
Port $SSH_PORT
IdentityFile ~/.ssh/staging.key
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}
- name: Update alpha environment
run: |
ssh staging 'export DOCKER_BRANCH=${{ github.ref_name }} DOCKER_REGISTRY=${{ secrets.DOCKER_REGISTRY }}
cd /var/docker/api/${DOCKER_BRANCH}
git pull origin ${{ github.ref_name }}
docker compose --file docker-compose-${{ github.ref_name }}.yml pull
docker login -u ${{ secrets.DOCKER_LOGIN }} -p ${{ secrets.DOCKER_PASSWD }} ${{ secrets.DOCKER_REGISTRY }}
docker compose --project-name ${{ github.ref_name }}-api_php --file docker-compose-${{ github.ref_name }}.yml up -d'
# Add migration !?