Skip to content

Commit

Permalink
#14: Improved .yml file x3.
Browse files Browse the repository at this point in the history
  • Loading branch information
ulin-evgeny committed May 25, 2024
1 parent b681cc1 commit d934199
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 29 deletions.
85 changes: 85 additions & 0 deletions .github/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: TestAndDeploy

on: push

env:
CI_PROJECT_NAME: sd-simpro-ng-int
CI_DOCKER_REGISTRY_URL: registry.digitalocean.com
CI_CD_REPOSITORY_NAME: RonasIT/sd-simpro-ng-int-dkc
CI_CD_REPOSITORY_EVENT_TYPE: trigger-deployment

jobs:

Tests:
runs-on: ubuntu-latest
env:
COMPOSE_FILE: .github/docker-compose.yml
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare .env
run: |
cp .env.testing .env
- name: Docker-Compose Up
run: |
docker-compose up -d
- name: Set Permissions
run: |
docker-compose exec -T nginx chown -R www-data:www-data /app
docker-compose exec -T nginx chmod -R 755 /app
- name: Prepare Containers
run: |
docker-compose exec -T nginx composer install
docker-compose exec -T nginx php artisan jwt:secret --env=testing
docker-compose exec -T nginx php artisan key:generate --env=testing
- name: Run Tests
run: |
docker-compose exec -T nginx php vendor/bin/phpunit --stop-on-failure ./tests/
- name: Logs
run: |
docker-compose exec -T nginx cat storage/logs/*.log || true
Deploy:
runs-on: ubuntu-latest
needs: Tests
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set Environment
run: |
if ${{ github.ref == 'refs/heads/main' }}; then
echo "CI_PROJECT_ENV_NAME=prod" >> $GITHUB_ENV
CI_PROJECT_ENV_NAME=prod
else
echo "CI_PROJECT_ENV_NAME=dev" >> $GITHUB_ENV
CI_PROJECT_ENV_NAME=dev
fi
echo "CI_DOCKER_IMAGE=$CI_DOCKER_REGISTRY_URL/$CI_PROJECT_NAME/$CI_PROJECT_NAME-$CI_PROJECT_ENV_NAME:${{ github.run_id }}" >> $GITHUB_ENV
- name: Create .env file
run: |
cp .env.$CI_PROJECT_ENV_NAME .env
- name: Set Up QEMU
uses: docker/setup-qemu-action@v1
- name: Set Up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login To DockerHub
uses: docker/login-action@v1
with:
registry: registry.digitalocean.com
username: ${{ secrets.DIGITAL_OCEAN_ACCESS_TOKEN }}
password: ${{ secrets.DIGITAL_OCEAN_ACCESS_TOKEN }}
- name: Build And Push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ env.CI_DOCKER_IMAGE }}
- name: Trigger Deployment
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.CI_CD_REPOSITORY_ACCESS_TOKEN }}
repository: ${{ env.CI_CD_REPOSITORY_NAME }}
event-type: ${{ env.CI_CD_REPOSITORY_EVENT_TYPE }}
client-payload: '{"image": "${{ env.CI_DOCKER_IMAGE }}", "env_name": "${{ env.CI_PROJECT_ENV_NAME }}", "project_name": "${{ env.CI_PROJECT_NAME }}"}'
28 changes: 0 additions & 28 deletions .github/docker-compose11.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/run-tests-with-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
Tests:
runs-on: ubuntu-latest
env:
COMPOSE_FILE: ./docker-compose.yml
COMPOSE_FILE: ./github/docker-compose.yml
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down

0 comments on commit d934199

Please sign in to comment.