Fix adminer access #36
This file contains hidden or 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: 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:9.3 | |
| 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.4'] | |
| 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.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' | |
| run: composer install --no-progress --prefer-dist --optimize-autoloader | |
| env: | |
| DATABASE_URL: mysql://root:[email protected]:${{ job.services.mysql.ports['3306'] }}/symfony | |
| - 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: composer require --dev phpunit/phpunit && vendor/bin/phpunit --coverage-text | |
| env: | |
| DATABASE_URL: mysql://root:[email protected]:${{ job.services.mysql.ports['3306'] }}/symfony | |
| deploy: | |
| name: Deploy image | |
| runs-on: ubuntu-latest | |
| needs: validate | |
| env: | |
| DOCKER_BRANCH: ${{ github.ref_name }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set environment variables | |
| run: | | |
| echo "DOCKER_NETWORK_NAME=api-${{ github.ref_name }}" >> $GITHUB_ENV | |
| if [[ "${{ github.ref_name }}" == "alpha" ]]; then | |
| echo "APP_ENV=dev" >> $GITHUB_ENV | |
| echo "DATABASE_URL=mysql://root:symfony@db:3306/symfony" >> $GITHUB_ENV | |
| else | |
| echo "APP_ENV=prod" >> $GITHUB_ENV | |
| echo "DATABASE_URL=mysql://root:symfony@db:3306/symfony" >> $GITHUB_ENV | |
| fi | |
| - 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 }} | |
| build-args: | | |
| APP_ENV=${{ env.APP_ENV }} | |
| DATABASE_URL=${{ env.DATABASE_URL }} | |
| - 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 }} | |
| DOMAIN_URL: ${{ secrets.DOMAIN_URL }} | |
| - name: Update envs & run migrations | |
| run: | | |
| if [[ "$DOCKER_BRANCH" == "master" ]]; then | |
| HOSTNAME="api.${{ secrets.DOMAIN_URL }}" | |
| APP_ENV="prod" | |
| elif [[ "$DOCKER_BRANCH" == "preprod" ]]; then | |
| HOSTNAME="api.$DOCKER_BRANCH.${{ secrets.DOMAIN_URL }}" | |
| APP_ENV="prod" | |
| else | |
| HOSTNAME="api.$DOCKER_BRANCH.${{ secrets.DOMAIN_URL }}" | |
| APP_ENV="dev" | |
| fi | |
| ssh staging "cd /var/docker/api/${DOCKER_BRANCH} && \ | |
| export DOCKER_BRANCH=${{ github.ref_name }} && \ | |
| export DOCKER_REGISTRY=${{ secrets.DOCKER_REGISTRY }} && \ | |
| echo 'APP_ENV=${APP_ENV}' > .env && \ | |
| echo 'DATABASE_URL=${DATABASE_URL}' >> .env && \ | |
| echo 'DOCKER_NETWORK_NAME=api-${DOCKER_BRANCH}' >> .env && \ | |
| echo 'HOSTNAME=${HOSTNAME}' >> .env && \ | |
| echo 'MYSQL_ROOT_PASSWORD=symfony' >> .env && \ | |
| echo 'MYSQL_USER=symfony' >> .env && \ | |
| echo 'MYSQL_PASSWORD=symfony' >> .env && \ | |
| echo 'MYSQL_DATABASE=symfony' >> .env && \ | |
| git pull origin ${DOCKER_BRANCH} && \ | |
| docker compose --file docker-compose-branch.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-branch.yml up -d && \ | |
| until docker exec ${{ github.ref_name }}-api_php-sf true 2>/dev/null; do sleep 5; done && \ | |
| docker compose --project-name ${{ github.ref_name }}-api_php --file docker-compose-branch.yml exec symfony php bin/console doctrine:migrations:migrate --no-interaction" |