diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 24fd6f3c..17f0cbb1 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -3,72 +3,26 @@ name: Ruby on: [push] jobs: - docker_build: - name: Build Dockerfile - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3.5.2 - - name: Build the Dockerfile - run: docker build -t app . build: - name: The Build + name: Build and test runs-on: ubuntu-latest - - services: - redis: - image: redis:4 - ports: - - 6379:6379 - postgres: - image: postgres:10 - env: - POSTGRES_DB: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - ports: ["5432:5432"] - # needed because the postgres container does not provide a healthcheck - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - - uses: actions/checkout@v3.5.2 + - uses: actions/checkout@v3 + - name: Copy .env file + uses: canastro/copy-file-action@master + with: + source: "env.example" + target: ".env" - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true + - name: Build the Stack + run: "docker compose build" - - name: Show available Ruby versions - run: | - ls $RUNNER_TOOL_CACHE/Ruby - uname -a - cat /etc/os-release + - name: Start dependencies + run: "docker compose up -d --no-deps db redis app" - - name: Install required packages - run: sudo apt-get install libpq-dev + - name: Run all tests + run: "docker compose exec app ./ci.sh" - - name: Test - run: | - RAILS_ENV=test bundle exec rails db:create - RAILS_ENV=test bundle exec rails db:schema:load - bundle exec rake - env: - #Note: DATABASE_URL does not work in TEST env. - TEST_DB_HOST: localhost - TEST_DB_USERNAME: postgres - TEST_DB_PASSWORD: postgres - TEST_DB_NAME: postgres - discourse_sso_secret: "secret" - discourse_endpoint: "https://example.com" - PG_PORT: ${{ job.services.postgres.ports['5432'] }} + - name: Teardown the stack + run: "docker compose down" - #- name: Deploy to server via SSH - #uses: appleboy/ssh-action@master - #with: - #host: ${{ secrets.HOST }} - #key: ${{ secrets.KEY }} - #port: ${{ secrets.PORT }} - #username: ${{ secrets.USERNAME }} - #script: | - #cd smartcitizen-api - #pwd - #./scripts/deploy.sh - #if: github.ref == 'refs/heads/master' && job.status == 'success' diff --git a/Dockerfile b/Dockerfile index 71c3e885..e100f3fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,6 +42,10 @@ ARG BUNDLE_WITHOUT ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT} RUN bundle install + +COPY package.json yarn.lock /app/ +RUN . $NVM_DIR/nvm.sh && nvm use default && yarn install + # Copy the Rails application into place COPY . /app diff --git a/ci.sh b/ci.sh new file mode 100755 index 00000000..09d1b4a3 --- /dev/null +++ b/ci.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -ae +git config --global --add safe.directory /app +source $NVM_DIR/nvm.sh +nvm use default +yarn install +NODE_OPTIONS=--openssl-legacy-provider bundle exec bin/rake assets:precompile +bundle exec bin/rake db:create +bundle exec bin/rake db:schema:load +unset DATABASE_URL +RAILS_ENV=test bundle exec bin/rake db:create +RAILS_ENV=test bundle exec bin/rake db:schema:load +bundle exec bin/rake spec diff --git a/compose.override.local.yml b/compose.override.local.yml index 269098cb..8d7d58d2 100644 --- a/compose.override.local.yml +++ b/compose.override.local.yml @@ -1,7 +1,5 @@ services: app: - build: - args: !reset [] restart: "no" sidekiq: restart: "no" diff --git a/compose.override.production.yml b/compose.override.production.yml new file mode 100644 index 00000000..85108bd6 --- /dev/null +++ b/compose.override.production.yml @@ -0,0 +1,12 @@ +version: '3.3' +services: + app: + build: + args: + - BUNDLE_WITHOUT=test development + mqtt: + entrypoint: ["echo", "MQTT service disabled in production"] + cassandra-1: + entrypoint: ["echo", "Cassandra service disabled in production"] + kairos: + depends_on: !reset [] diff --git a/compose.override.staging.yml b/compose.override.staging.yml new file mode 100644 index 00000000..2a56050e --- /dev/null +++ b/compose.override.staging.yml @@ -0,0 +1,27 @@ +services: + db: + deploy: + resources: + limits: + memory: 2gb + app: + build: + args: + - BUNDLE_WITHOUT=test development + mqtt: + entrypoint: ["echo", "MQTT service disabled on staging"] + mqtt-task-main-1: + environment: + MQTT_CLIENT_ID: smartcitizen-staging-api-main-1 + mqtt-task-main-2: + environment: + MQTT_CLIENT_ID: smartcitizen-staging-api-main-2 + mqtt-task-secondary: + environment: + MQTT_CLIENT_ID: "smartcitizen-staging-api-secondary" + + +# cassandra-1: +# entrypoint: ["echo", "Cassandra service disabled on staging"] +# kairos: +# depends_on: !reset [] diff --git a/compose/app.yml b/compose/app.yml index d729e4d9..46322128 100644 --- a/compose/app.yml +++ b/compose/app.yml @@ -2,10 +2,6 @@ services: app: build: context: ../. - # Skip installing development & test gems in production, saves 20s build time. - # If developing with Docker, this line might need to be commented out. - args: - - BUNDLE_WITHOUT=test development env_file: ../.env ports: - "3000:3000" diff --git a/env.example b/env.example index fcdd837d..6bb146b2 100644 --- a/env.example +++ b/env.example @@ -10,6 +10,7 @@ DATABASE_URL=postgresql://postgres:postgres@db/sc_dev TEST_DB_HOST=db TEST_DB_USERNAME=postgres +TEST_DB_PASSWORD=postgres # Tell sidekiq to use hostname redis, not localhost # If this var is set, Redis uses it by default. No config needed @@ -44,3 +45,7 @@ PROMETHEUS_URL= PROMETHEUS_USERNAME= PROMETHEUS_PASSWORD= PROMETHEUS_INSTANCE_LABEL= + + +discourse_sso_secret="InsertDiscourseSSOSecretHERE" +discourse_endpoint="http://example.com"