Merge pull request #281 from devcordde/dependabot/gradle/ch.qos.logba… #897
This file contains 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: CI | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '*' | |
pull_request: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: gradle/wrapper-validation-action@v1 | |
timeout-minutes: 1 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 17 | |
- name: Build with Gradle | |
run: ./gradlew --build-cache build -x test | |
timeout-minutes: 30 | |
- name: Test with Gradle | |
run: ./gradlew --build-cache test | |
timeout-minutes: 30 | |
build-docker: | |
runs-on: ubuntu-latest | |
environment: gitlab-docker-registry | |
needs: | |
- build | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 17 | |
- name: Create Docker layers | |
run: ./gradlew buildLayers dockerfile | |
timeout-minutes: 10 | |
- name: Build Docker Image | |
run: docker build . -t registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }} | |
timeout-minutes: 30 | |
working-directory: backend/build/docker/main | |
- name: Login to GitLab Registry | |
if: github.event_name == 'push' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') | |
run: echo ${{ secrets.DOCKER_PUSH_TOKEN }} | docker login -u ${{ secrets.DOCKER_PUSH_TOKEN_NAME }} --password-stdin registry.gitlab.com | |
timeout-minutes: 1 | |
- name: Push Docker Image | |
if: github.event_name == 'push' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') | |
run: docker push registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }} | |
timeout-minutes: 30 | |
- name: Tag & Push latest Docker Image | |
if: github.ref_name == 'main' || github.ref_type == 'tag' | |
run: | | |
docker image tag registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }} registry.gitlab.com/taucher2003-group/devmarkt-backend:latest | |
docker push registry.gitlab.com/taucher2003-group/devmarkt-backend:latest | |
- name: Tag & Push tag Docker Image | |
if: github.ref_type == 'tag' | |
run: | | |
docker image tag registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }} registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.ref_name }} | |
docker push registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.ref_name }} | |
- name: Store Image as artifact if running as fork | |
if: github.event_name != 'push' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]') | |
run: docker save registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }} > qa-image.tar | |
- name: Upload stored Images as artifact | |
if: github.event_name != 'push' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]') | |
uses: actions/upload-artifact@v4 | |
with: | |
name: qa-image | |
path: qa-image.tar | |
qa: | |
runs-on: ubuntu-latest | |
needs: | |
- build-docker | |
services: | |
postgres: | |
image: postgres:14.2 | |
env: | |
POSTGRES_PASSWORD: devmarkt-qa | |
POSTGRES_USER: devmarkt-qa | |
POSTGRES_DB: devmarkt-qa | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: '16' | |
- name: Download stored image as artifact | |
if: github.event_name != 'push' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]') | |
uses: actions/download-artifact@v4 | |
with: | |
name: qa-image | |
path: qa-image.tar | |
- name: Load stored image if running as fork | |
if: github.event_name != 'push' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]') | |
run: docker load -i qa-image.tar/qa-image.tar | |
- name: Start backend | |
run: | | |
docker network create --subnet=172.16.0.0/16 backend-network | |
docker run -d --name backend -p 8080:8080 -e MICRONAUT_ENVIRONMENTS=qa -e DEVMARKT_POSTGRES_HOST=172.16.0.1 -e DEVMARKT_POSTGRES_DATABASE=devmarkt-qa -e DEVMARKT_POSTGRES_USER=devmarkt-qa -e DEVMARKT_POSTGRES_PASSWORD=devmarkt-qa registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }} | |
docker network connect --ip 172.16.0.2 backend-network backend | |
- name: Install dependencies | |
run: yarn install | |
working-directory: qa | |
- name: Check if backend is reachable | |
run: curl --fail -sv --retry 3 --retry-delay 3 --retry-connrefused http://172.16.0.2:8080/health | |
- name: Run Tests | |
run: BACKEND_HOST=http://172.16.0.2:8080 yarn test:ci | |
working-directory: qa | |
- name: Stop backend | |
if: always() | |
run: | | |
docker stop backend | |
docker logs backend | |
docker rm backend | |
docker network rm backend-network |