From bc4b4bc81db17392ff8df8c99867976b59d2a68a Mon Sep 17 00:00:00 2001 From: Tristan van Triest Date: Wed, 4 Dec 2024 11:41:17 +0100 Subject: [PATCH] Update other deploy scripts --- .github/workflows/deploy.yml | 54 +++++++++++++++++++++++++++ .github/workflows/main_test.yml | 65 --------------------------------- .github/workflows/test.yml | 12 +++--- 3 files changed, 60 insertions(+), 71 deletions(-) delete mode 100644 .github/workflows/main_test.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 613d048..5b8f821 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -11,6 +11,60 @@ on: - main jobs: + build_and_test: + name: Build and test + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + token: ${{ secrets.SHARED_PAT }} + submodules: recursive + + - name: Build and start services + run: | + docker compose -f docker-compose.test.yml up -d database + sleep 10 # Adjust sleep time as needed to allow services to start + + - name: Wait for database to be ready + run: | + until docker compose -f docker-compose.test.yml exec -T database pg_isready -U postgres; do + >&2 echo "Postgres is unavailable - sleeping" + sleep 1 + done + - name: Start app service + run: docker compose -f docker-compose.test.yml up --force-recreate --build --exit-code-from app app --remove-orphans + + - name: Clean up + if: always() + run: docker compose -f docker-compose.test.yml down + build_and_push: + name: Build and push to ACR + needs: build_and_test + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + token: ${{ secrets.SHARED_PAT }} + submodules: recursive + - name: Log in to Azure Container Registry + run: | + echo "${{ secrets.AZURE_PASSWORD }}" | docker login "${{ secrets.ACR_REGISTRY }}" --username "${{ secrets.AZURE_APP_ID }}" --password-stdin + + - name: Set version + run: echo "VERSION=${{ github.run_number }}" >> $GITHUB_ENV + + - name: Build Docker Image with both tags + run: | + docker build -t ${{ secrets.ACR_REGISTRY }}/tristanvantriest/gtfs-rt:latest \ + -t ${{ secrets.ACR_REGISTRY }}/tristanvantriest/gtfs-rt:${{ env.VERSION }} \ + -f Dockerfile . + + - name: Push Docker Image to ACR with both tags + run: | + docker push ${{ secrets.ACR_REGISTRY }}/tristanvantriest/gtfs-rt:latest + docker push ${{ secrets.ACR_REGISTRY }}/tristanvantriest/gtfs-rt:${{ env.VERSION }} deploy: name: Deploy to Production if: github.event.pull_request.merged == true || github.event_name == 'push' diff --git a/.github/workflows/main_test.yml b/.github/workflows/main_test.yml deleted file mode 100644 index ede431e..0000000 --- a/.github/workflows/main_test.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Test service and push - -on: - push: - branches: - - 'main' - pull_request: - branches: - - 'main' - -jobs: - build_and_test: - name: Build and test - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - token: ${{ secrets.SHARED_PAT }} - submodules: recursive - - - name: Build and start services - run: | - docker compose -f docker-compose.test.yml up -d database - sleep 10 # Adjust sleep time as needed to allow services to start - - - name: Wait for database to be ready - run: | - until docker compose -f docker-compose.test.yml exec -T database pg_isready -U postgres; do - >&2 echo "Postgres is unavailable - sleeping" - sleep 1 - done - - name: Start app service - run: docker compose -f docker-compose.test.yml up --force-recreate --build --exit-code-from app app --remove-orphans - - - name: Clean up - if: always() - run: docker compose -f docker-compose.test.yml down - build_and_push: - needs: build_and_test - name: Build and push to ACR - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - token: ${{ secrets.SHARED_PAT }} - submodules: recursive - - name: Log in to Azure Container Registry - run: | - echo "${{ secrets.AZURE_PASSWORD }}" | docker login "${{ secrets.ACR_REGISTRY }}" --username "${{ secrets.AZURE_APP_ID }}" --password-stdin - - - name: Set version - run: echo "VERSION=${{ github.run_number }}" >> $GITHUB_ENV - - - name: Build Docker Image with both tags - run: | - docker build -t ${{ secrets.ACR_REGISTRY }}/tristanvantriest/gtfs-rt:latest \ - -t ${{ secrets.ACR_REGISTRY }}/tristanvantriest/gtfs-rt:${{ env.VERSION }} \ - -f Dockerfile . - - - name: Push Docker Image to ACR with both tags - run: | - docker push ${{ secrets.ACR_REGISTRY }}/tristanvantriest/gtfs-rt:latest - docker push ${{ secrets.ACR_REGISTRY }}/tristanvantriest/gtfs-rt:${{ env.VERSION }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dea8235..997ab85 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,13 +2,13 @@ name: Test service on: push: - branches: - - '**' - - '!main' + branches-ignore: + - main pull_request: - branches: - - '**' - - '!main' + types: + - opened + - reopened + - synchronize jobs: build_and_test: