From e971073ac41de355839e5f1ff903a36828a4e64b Mon Sep 17 00:00:00 2001 From: Quentin Treheux <58399237+LuciferBahamut@users.noreply.github.com> Date: Wed, 25 Jan 2023 07:40:05 +0100 Subject: [PATCH] Make CI works (#121) Co-authored-by: GitBluub --- .github/workflows/CI.yml | 191 +++++++++++++++++++++++++++++++ .github/workflows/build.yml | 38 ------ .github/workflows/docker.yml | 38 ------ .github/workflows/node.js.yml | 31 ----- .github/workflows/robot.yml | 34 ------ .github/workflows/unit-tests.yml | 26 ----- docker-compose.prod.yml | 41 +++++++ 7 files changed, 232 insertions(+), 167 deletions(-) create mode 100644 .github/workflows/CI.yml delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/docker.yml delete mode 100644 .github/workflows/node.js.yml delete mode 100644 .github/workflows/robot.yml delete mode 100644 .github/workflows/unit-tests.yml create mode 100644 docker-compose.prod.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..f326906 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,191 @@ +name: CI + +on: + push: + branches: + - '*' + pull_request: + branches: [ main ] + +jobs: + +## Build Back ## + + Build_Back: + runs-on: ubuntu-latest + timeout-minutes: 10 + defaults: + run: + working-directory: ./back + environment: Staging + + steps: + - uses: actions/checkout@v3 + + - name: Build Docker + run: docker build -t testback . + +## Build App ## + + Build_Front: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./front + environment: Staging + + steps: + - uses: actions/checkout@v3 + + - name: Install Yarn + run: npm install -g yarn + + - name: Install dependencies + run: yarn install + + - name: 🏗 Setup Expo + uses: expo/expo-github-action@v7 + with: + expo-version: latest + eas-version: 3.3.1 + token: ${{ secrets.EXPO_TOKEN }} + + - name: Build Android APK + run: | + eas build -p android --profile debug --local --non-interactive + mv *.apk chromacase.apk + + - name: Upload Artifact + if: github.ref == 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: chromacase.apk + path: front/ + +## Test Backend ## + + Test_Back: + runs-on: ubuntu-latest + timeout-minutes: 15 + needs: [ Build_Back ] + environment: Staging + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + fetch-depth: 0 + + - name: Copy env file to github secret env file + run: | + touch .env + echo "POSTGRES_USER=user" >> .env + echo "POSTGRES_PASSWORD=eip" >> .env + echo "POSTGRES_NAME=chromacase" >> .env + echo "POSTGRES_HOST=db" >> .env + echo "DATABASE_URL=postgresql://user:eip@db:5432/chromacase" >> .env + echo "JWT_SECRET=wow" >> .env + echo "POSTGRES_DB=chromacase" >> .env + echo "API_URL=http://localhost:80/api" >> .env + + - name: Start the service + run: docker-compose up -d back db + + - name: Perform healthchecks + run: | + docker-compose ps -a + wget --retry-connrefused http://localhost:3000 # /healthcheck + + - name: Run robot tests + run: | + pip install -r back/test/robot/requirements.txt + robot -d out back/test/robot/ + - uses: actions/upload-artifact@v3 + if: always() + with: + name: results + path: out + + - name: Write results to Pull Request and Summarry + if: always() && github.event_name == 'pull_request' + uses: joonvena/robotframework-reporter-action@v2.1 + with: + report_path: out/ + gh_access_token: ${{ secrets.GITHUB_TOKEN }} + only_summary: false + + - name: Write results to Summarry + if: always() && github.event_name != 'pull_request' + uses: joonvena/robotframework-reporter-action@v2.1 + with: + report_path: out/ + gh_access_token: ${{ secrets.GITHUB_TOKEN }} + only_summary: true + + - name: Remove .env && stop the service + run: docker-compose down && rm .env + +## Test App ## + +## Deployement ## + + Deployement_Docker: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + needs: [ Test_Back ] + environment: Production + + steps: + - uses: actions/checkout@v2 + + - name: Docker meta back + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{github.repository_owner}}/back + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to ghcr + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{github.repository_owner}} + password: ${{secrets.GITHUB_TOKEN}} + - + name: Build and push + uses: docker/build-push-action@v3 + with: + context: ./back + push: true + tags: ${{steps.meta.outputs.tags}} + - name: Docker meta front + id: meta_front + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{github.repository_owner}}/front + - + name: Build and push front + uses: docker/build-push-action@v3 + with: + context: ./front + push: true + tags: ${{steps.meta_front.outputs.tags}} + build-args: API_URL=${{secrets.API_URL}} + - name: Docker meta scorometer + id: meta_scorometer + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{github.repository_owner}}/scorometer + - + name: Build and push scorometer + uses: docker/build-push-action@v3 + with: + context: ./scorometer + push: true + tags: ${{steps.meta_scorometer.outputs.tags}} + diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 759a7b0..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Build - -on: - push: - branches: - - '*' - pull_request: - branches: [ main ] - workflow_dispatch: - -jobs: - build_front: - runs-on: ubuntu-latest - defaults: - run: - working-directory: ./front - steps: - - uses: actions/checkout@v3 - - name: Install Yarn - run: npm install -g yarn - - name: Install dependencies - run: yarn install - - name: 🏗 Setup Expo - uses: expo/expo-github-action@v7 - with: - expo-version: latest - eas-version: latest - token: ${{ secrets.EXPO_TOKEN }} - - name: Build Android APK - run: | - eas build -p android --profile debug --local --non-interactive - mv *.apk chromacase.apk - - name: Upload Artifact - uses: actions/upload-artifact@v1 - with: - name: chromacase.apk - path: front/ - \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index da7ed2c..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: docker - -on: - push: - branches: - - 'main' - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - images: ghcr.io/${{github.repository_owner}}/back - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to ghcr - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{github.repository_owner}} - password: ${{secrets.GITHUB_TOKEN}} - - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: ./back - push: true - tags: ${{steps.meta.outputs.tags}} diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml deleted file mode 100644 index 6404516..0000000 --- a/.github/workflows/node.js.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Node.js CI - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - os_matrix: - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [12.x, 14.x, 16.x] - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - cache-dependency-path: 'back/package-lock.json' - - - name: run npm commands - working-directory: back - run: | - npm install - npm test diff --git a/.github/workflows/robot.yml b/.github/workflows/robot.yml deleted file mode 100644 index e581a23..0000000 --- a/.github/workflows/robot.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: RobotTests -on: [push, pull_request, workflow_dispatch] - -jobs: - build: - runs-on: ubuntu-latest - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - fetch-depth: 0 - - - name: Build the app - run: docker-compose build - - - name: Start the service - run: docker-compose up -d - - - name: Perform healthchecks - run: | - docker-compose ps -a - wget --retry-connrefused http://localhost:3000 # /healthcheck - - - name: Run robot tests - run: | - pip install -r back/tests/robot/requirements.txt - robot -d out back/tests/robot/ - - - uses: actions/upload-artifact@v2 - with: - name: results - path: out - diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml deleted file mode 100644 index 4f4ef46..0000000 --- a/.github/workflows/unit-tests.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Unit Tests - -on: - push: - branches: - - '*' - pull_request: - branches: [ main ] - workflow_dispatch: - -jobs: - run_front_unit_tests: - runs-on: ubuntu-latest - defaults: - run: - working-directory: ./front - steps: - - uses: actions/checkout@v3 - - name: Install Yarn - run: npm install -g yarn - - name: Install Jest - run: yarn global add jest - - name: Install dependencies - run: yarn install - - name: Run Unit tests - run: yarn test \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..819c749 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,41 @@ +services: + back: + image: ghcr.io/chroma-case/back:main + ports: + - "3000:3000" + depends_on: + db: + condition: service_healthy + env_file: + - .env + volumes: + - ./musics:/musics + scorometer: + image: ghcr.io/chroma-case/scorometer:main + ports: + - "6543:6543" + volumes: + - ./musics:/musics + db: + container_name: db + image: postgres:alpine3.14 + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] + interval: 5s + timeout: 5s + retries: 5 + + front: + image: ghcr.io/chroma-case/front:main + ports: + - "80:80" + depends_on: + - "back" + env_file: + - .env