From c1f822738f56681888d58c35af14aee963033595 Mon Sep 17 00:00:00 2001 From: Aidan Lavis Date: Mon, 4 Sep 2023 16:44:17 -0400 Subject: [PATCH] Fix MySQL CI setup (#1) Use Docker --- .github/workflows/main.yml | 31 ++++++++++--------------------- Dockerfile | 4 +++- docker-compose.yml | 10 ++++++++-- spec/trilogy_aurora_spec.rb | 6 +++--- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f2d2e09..6c0f94b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,21 +12,8 @@ on: jobs: test: runs-on: ubuntu-latest - services: - mysql: - image: mysql:8.0 - env: - MYSQL_ALLOW_EMPTY_PASSWORD: yes - MYSQL_DATABASE: trilogy-aurora-test - ports: - - 3306 - options: >- - --health-cmd="mysqladmin ping" - --health-interval=10s - --health-timeout=5s - --health-retries=3 name: Test Ruby ${{ matrix.ruby }} - timeout-minutes: 10 + timeout-minutes: 5 strategy: fail-fast: false matrix: @@ -35,15 +22,17 @@ jobs: - '3.1' - '3.2' + env: + RUBY_VERSION: ${{ matrix.ruby }} + steps: - uses: actions/checkout@v3 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run tests - run: bundle exec rake spec + - name: Docker Build + run: docker-compose build --build-arg RUBY_VERSION=$RUBY_VERSION + - name: Docker MySQL Healthcheck + run: docker-compose run --rm app echo "MySQL Healthy" + - name: Run tests with Docker + run: docker-compose run --rm app ./bin/test rubocop: runs-on: ubuntu-latest diff --git a/Dockerfile b/Dockerfile index d07f268..afaf10a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM ruby:3.2-alpine +ARG RUBY_VERSION=3.2 + +FROM ruby:${RUBY_VERSION}-alpine # Create application directory. RUN mkdir /app diff --git a/docker-compose.yml b/docker-compose.yml index 213289a..9274605 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,9 +9,15 @@ services: volumes: - .:/app depends_on: - - mysql + mysql: + condition: service_healthy mysql: image: mysql:8.0 environment: MYSQL_ROOT_PASSWORD: '' - MYSQL_ALLOW_EMPTY_PASSWORD: true + MYSQL_ALLOW_EMPTY_PASSWORD: 1 + healthcheck: + test: ["CMD-SHELL", "mysqladmin ping -h mysql"] + interval: 10s + timeout: 5s + retries: 3 diff --git a/spec/trilogy_aurora_spec.rb b/spec/trilogy_aurora_spec.rb index f8d1082..e881122 100644 --- a/spec/trilogy_aurora_spec.rb +++ b/spec/trilogy_aurora_spec.rb @@ -5,9 +5,9 @@ let :trilogy do Trilogy.new( - host: ENV.fetch("TEST_DB_HOST", nil), - username: ENV.fetch("TEST_DB_USER", nil), - password: ENV.fetch("TEST_DB_PASS", nil), + host: ENV.fetch("TEST_DB_HOST"), + username: ENV.fetch("TEST_DB_USER"), + password: ENV.fetch("TEST_DB_PASS"), aurora_max_retry: 10, aurora_disconnect_on_readonly: aurora_disconnect_on_readonly )