From e406079510566bd32d99ca95b8f85aad6f02fedb Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 23 Jun 2022 15:36:38 +0200 Subject: [PATCH 1/4] feat: add CI for backend --- .github/workflows/main.yml | 151 ++++++++++++------------------------- 1 file changed, 48 insertions(+), 103 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0416b76..dc4cb7f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,114 +1,59 @@ -# This is a basic workflow to help you get started with Actions +name: CI RSpec Tests -name: CI-CD - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the main branch +on: [push, pull_request] push: - branches: [main] + paths: + - 'api/**' pull_request: - branches: [main] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: + paths: + - 'api/**' -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains multiple jobs - build_test: - # The type of runner that the job will run on + build: + name: CI runs-on: ubuntu-latest - strategy: - matrix: - node-version: [14.x] + env: + api-dir: ./api/backend + + services: + postgres: + image: postgres:11.6 + ports: ["5432:5432"] + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + redis: + image: redis + ports: ["6379:6379"] + elasticsearch: + image: elasticsearch:6.8.8 + ports: ["9200:9200"] + options: -e="discovery.type=single-node" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10 - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - # Runs a single command using the runners shell - - name: Setup Node.js - uses: actions/setup-node@master + - uses: actions/checkout@v1 + - uses: actions/setup-ruby@v1 with: - node-version: ${{ matrix.node-version }} - - # Install app dependencies - - name: Install Dependencies - run: | - cd node - npm ci - # Build and test the app - - name: Build and test - run: | - cd node - npm run build:prod - npm run test - push_to_docker_hub: - runs-on: ubuntu-latest - # Build Docker image and push to Docker Hub only if the app build and test is successfull - needs: [build_test] - - steps: - - name: Checkout repo - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + ruby-version: 2.6.6 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Install PostgreSQL + run: sudo apt-get -yqq install libpq-dev - - name: Build and push - uses: docker/build-push-action@v2 - with: - # This path is totally independant from the 'file' directve below - context: ./node - # This path is totally independant from the 'context' directive above - file: ./node/Dockerfile.prod - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/node-docker-deploy:latest -# I left this job here only for reference. As in Dockerfile I use the -# distroless image (i.e. it doesn't have shell), this step is impossible -# to execute -# -# - name: Run the image in a container -# uses: addnab/docker-run-action@v3 -# with: -# image: ${{ secrets.DOCKERHUB_USERNAME }}/node-docker-deploy:latest -# run: | -# echo "running the docker image" -# echo "Testing the nodejs app endpoints" -# echo ${{ steps.docker_build.outputs.digest }} - - deploy: - runs-on: ubuntu-latest - needs: [push_to_docker_hub] - - steps: - - name: Deploy to VPS - uses: appleboy/ssh-action@master - # TODO: add env vars as secrets on GitHub - with: - # VPS IP - host: ${{ secrets.VPS_SSH_HOST }} - # VPS username - username: ${{ secrets.VPS_SSH_USERNAME }} - # SSH key (copy it from your local machine) - key: ${{ secrets.VPS_SSH_SECRET }} - # SSH port - port: ${{ secrets.VPS_SSH_PORT }} - script: | - echo "Pull new image" - docker-compose -f /home/${{ secrets.VPS_SSH_USERNAME }}/node-docker-deploy/docker-compose.yml pull - echo "Restart the container" - docker-compose -f /home/${{ secrets.VPS_SSH_USERNAME }}/node-docker-deploy/docker-compose.yml up --force-recreate --build --no-deps -d - echo "Delete old image" - docker image prune -f \ No newline at end of file + - name: Run bundle install + working-directory: ${{env.api-dir}} + run: | + gem install bundler + bundle install --jobs 4 --retry 3 + - name: Setup Database + working-directory: ${{env.api-dir}} + env: + RAILS_ENV: test + PGHOST: localhost + PGUSER: postgres + run: bin/rails db:create db:schema:load + + - name: Build and test with rspec + working-directory: ${{env.api-dir}} + env: + RAILS_ENV: test + PGHOST: localhost + PGUSER: postgres + run: bundle exec rspec spec \ No newline at end of file From b82550ae29fdefc737a94e234a6bdc17eea88045 Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 23 Jun 2022 15:38:52 +0200 Subject: [PATCH 2/4] fix: CI for backend --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dc4cb7f..075ed82 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,6 @@ name: CI RSpec Tests -on: [push, pull_request] +on: [push] push: paths: - 'api/**' From 362143f387e092ce51778657a2f71899d38f0e9a Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 23 Jun 2022 15:41:31 +0200 Subject: [PATCH 3/4] fix: CI for backend --- .github/workflows/github-actions-demo.yml | 17 +++++++++++++++++ .github/workflows/main.yml | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml new file mode 100644 index 0000000..75be101 --- /dev/null +++ b/.github/workflows/github-actions-demo.yml @@ -0,0 +1,17 @@ +name: GitHub Actions Demo +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v3 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 075ed82..dc4cb7f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,6 @@ name: CI RSpec Tests -on: [push] +on: [push, pull_request] push: paths: - 'api/**' From 2900ff20de2765c0758533c51614a2a8789b4f3f Mon Sep 17 00:00:00 2001 From: Kevin Date: Sun, 3 Jul 2022 12:13:33 +0200 Subject: [PATCH 4/4] feat: update main.yml --- .github/workflows/main.yml | 84 ++++++++++++++++++--------------- api/backend/config/database.yml | 3 ++ mobile/pubspec.lock | 2 +- 3 files changed, 49 insertions(+), 40 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dc4cb7f..d2b5cd9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,59 +1,65 @@ -name: CI RSpec Tests - -on: [push, pull_request] - push: - paths: - - 'api/**' - pull_request: - paths: - - 'api/**' +name: Rails +on: push jobs: - build: - name: CI + verify: + name: Build runs-on: ubuntu-latest - env: - api-dir: ./api/backend services: postgres: - image: postgres:11.6 + image: postgres:11 + env: + POSTGRES_USER: rails_github_actions + POSTGRES_DB: rails_github_actions_test + POSTGRES_PASSWORD: postgres ports: ["5432:5432"] - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - redis: - image: redis - ports: ["6379:6379"] - elasticsearch: - image: elasticsearch:6.8.8 - ports: ["9200:9200"] - options: -e="discovery.type=single-node" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + # if you need redis + # redis: + # image: redis + # ports: + # - 6379:6379 + # options: --entrypoint redis-server steps: - uses: actions/checkout@v1 - - uses: actions/setup-ruby@v1 + - name: Set up Ruby + uses: actions/setup-ruby@v1 with: - ruby-version: 2.6.6 - - - name: Install PostgreSQL - run: sudo apt-get -yqq install libpq-dev - - - name: Run bundle install - working-directory: ${{env.api-dir}} + ruby-version: 2.6.x + - name: Set up Node + uses: actions/setup-node@v1 + with: + node-version: 10.13.0 + - name: Install dependencies run: | + sudo apt-get -yqq install libpq-dev build-essential libcurl4-openssl-dev gem install bundler bundle install --jobs 4 --retry 3 - - name: Setup Database - working-directory: ${{env.api-dir}} + yarn install + - name: Setup test database env: RAILS_ENV: test PGHOST: localhost - PGUSER: postgres - run: bin/rails db:create db:schema:load + POSTGRES_DB: rails_github_actions_test + POSTGRES_USER: rails_github_actions + POSTGRES_PASSWORD: postgres + run: | + cp config/database.ci.yml config/database.yml + rake db:create db:migrate - - name: Build and test with rspec - working-directory: ${{env.api-dir}} + - name: Run tests env: - RAILS_ENV: test PGHOST: localhost - PGUSER: postgres - run: bundle exec rspec spec \ No newline at end of file + POSTGRES_DB: rails_github_actions_test + POSTGRES_USER: rails_github_actions + POSTGRES_PASSWORD: postgres + PGPORT: ${{ job.services.postgres.ports[5432] }} + RAILS_ENV: test + run: rspec \ No newline at end of file diff --git a/api/backend/config/database.yml b/api/backend/config/database.yml index 97b2a12..3a7c56f 100755 --- a/api/backend/config/database.yml +++ b/api/backend/config/database.yml @@ -18,6 +18,9 @@ default: &default adapter: postgresql encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + username: root + password: password + host: db development: <<: *default diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock index 51c1fa5..b5ed2dd 100644 --- a/mobile/pubspec.lock +++ b/mobile/pubspec.lock @@ -475,7 +475,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "5.3.1" + version: "6.1.0" sdks: dart: ">=2.17.0-0 <3.0.0" flutter: ">=2.8.1"