From 4d428df380e5d2c05ce4e500e1df3d6195fe0e56 Mon Sep 17 00:00:00 2001 From: Viachaslau Tyshkavets Date: Fri, 9 Jan 2026 11:08:24 +0400 Subject: [PATCH 1/9] chore: ci workflow --- .github/workflows/ci.yml | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0228bf6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,83 @@ +name: ci + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:9.6 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: blog_development + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 5s + --health-timeout 5s + --health-retries 10 + env: + PGHOST: localhost + PGPORT: 5432 + PGUSER: postgres + PGPASSWORD: postgres + PGDATABASE: blog_development + DATABASE_URL: postgres://postgres:postgres@localhost:5432/blog_development + steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "2.3.3" + + - name: Install system deps + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + build-essential \ + libpq-dev \ + libxml2-dev \ + libxslt1-dev \ + nodejs \ + zlib1g-dev + + - name: Install bundler + run: gem install bundler -v 1.10.6 + + - name: Configure bundler for nokogiri + run: bundle config build.nokogiri --use-system-libraries + + - name: Install gems + run: bundle install + + - name: Wait for postgres + run: | + for i in $(seq 1 30); do + bundle exec ruby -e "require 'pg'; PG.connect(host: ENV['PGHOST'], port: ENV['PGPORT'].to_i, dbname: ENV['PGDATABASE'], user: ENV['PGUSER'], password: ENV['PGPASSWORD']);" && exit 0 + sleep 2 + done + exit 1 + + - name: Setup database + run: bundle exec rake db:create db:migrate db:seed + + - name: Start server + run: | + bundle exec rails server -b 0.0.0.0 -p 3000 >tmp/rails.log 2>&1 & + for i in $(seq 1 30); do + curl -sSf http://localhost:3000 >/dev/null && exit 0 + sleep 2 + done + echo "Server failed to start" + tail -n 200 tmp/rails.log + exit 1 + + - name: Check homepage + run: curl -sSf http://localhost:3000 | grep -F "Home" From 25bf6ba219976edabbd02697dc7ac6c5b7c11be6 Mon Sep 17 00:00:00 2001 From: Viachaslau Tyshkavets Date: Fri, 9 Jan 2026 11:57:29 +0400 Subject: [PATCH 2/9] chore: pin container --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0228bf6..3629dfa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,8 @@ on: jobs: test: runs-on: ubuntu-latest + container: + image: ruby:2.3 services: postgres: image: postgres:9.6 @@ -39,8 +41,8 @@ jobs: - name: Install system deps run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ + apt-get update + apt-get install -y --no-install-recommends \ build-essential \ libpq-dev \ libxml2-dev \ From abbe37f83c9a0fb93f24aac184d85a63f77f24e6 Mon Sep 17 00:00:00 2001 From: Viachaslau Tyshkavets Date: Fri, 9 Jan 2026 12:02:07 +0400 Subject: [PATCH 3/9] chore: switch container to buildpack-deps:buster --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3629dfa..97fc9e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: test: runs-on: ubuntu-latest container: - image: ruby:2.3 + image: buildpack-deps:buster services: postgres: image: postgres:9.6 From acc8d1722362b6761791625260707ffc7a9dbc4d Mon Sep 17 00:00:00 2001 From: Viachaslau Tyshkavets Date: Fri, 9 Jan 2026 12:41:19 +0400 Subject: [PATCH 4/9] chore: ruby 2.3.3 on the fly build --- .github/workflows/ci.yml | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97fc9e5..ad8002c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,20 +35,30 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: "2.3.3" - - name: Install system deps run: | apt-get update apt-get install -y --no-install-recommends \ - build-essential \ - libpq-dev \ - libxml2-dev \ - libxslt1-dev \ - nodejs \ - zlib1g-dev + build-essential \ + libffi-dev \ + libgdbm-dev \ + libpq-dev \ + libreadline-dev \ + libssl-dev \ + libxml2-dev \ + libxslt1-dev \ + nodejs \ + libyaml-dev \ + zlib1g-dev + + - name: Install Ruby 2.3.3 + env: + RUBY_PREFIX: /opt/ruby-2.3.3 + run: | + git clone --depth=1 https://github.com/rbenv/ruby-build.git /tmp/ruby-build + /tmp/ruby-build/install.sh + ruby-build 2.3.3 "$RUBY_PREFIX" + echo "$RUBY_PREFIX/bin" >> "$GITHUB_PATH" - name: Install bundler run: gem install bundler -v 1.10.6 From 3ac126ff43001ae053a26000cd37be6bcecae52f Mon Sep 17 00:00:00 2001 From: Viachaslau Tyshkavets Date: Fri, 9 Jan 2026 12:46:25 +0400 Subject: [PATCH 5/9] chore(ci): pin buster apt mirrors --- .github/workflows/ci.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad8002c..ad0f0b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,10 +35,16 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Point apt to Debian archive + run: | + sed -i 's|deb.debian.org/debian|archive.debian.org/debian|g' /etc/apt/sources.list + sed -i 's|security.debian.org/debian-security|archive.debian.org/debian-security|g' /etc/apt/sources.list + sed -i '/buster-updates/d' /etc/apt/sources.list + - name: Install system deps run: | - apt-get update - apt-get install -y --no-install-recommends \ + apt-get -o Acquire::Check-Valid-Until=false -o Acquire::AllowInsecureRepositories=true update + apt-get -o Acquire::Check-Valid-Until=false -o Acquire::AllowInsecureRepositories=true install -y --no-install-recommends \ build-essential \ libffi-dev \ libgdbm-dev \ From 9d4cd492436dbb00a57aae2700a505cbc133ada7 Mon Sep 17 00:00:00 2001 From: Viachaslau Tyshkavets Date: Fri, 9 Jan 2026 12:56:41 +0400 Subject: [PATCH 6/9] chore: postgres service/host fixes --- .github/workflows/ci.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad0f0b9..ad775c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,17 +21,18 @@ jobs: ports: - 5432:5432 options: >- + --name postgres --health-cmd "pg_isready -U postgres" --health-interval 5s --health-timeout 5s --health-retries 10 env: - PGHOST: localhost + PGHOST: postgres PGPORT: 5432 PGUSER: postgres PGPASSWORD: postgres PGDATABASE: blog_development - DATABASE_URL: postgres://postgres:postgres@localhost:5432/blog_development + DATABASE_URL: postgres://postgres:postgres@postgres:5432/blog_development steps: - uses: actions/checkout@v4 @@ -78,10 +79,10 @@ jobs: - name: Wait for postgres run: | for i in $(seq 1 30); do - bundle exec ruby -e "require 'pg'; PG.connect(host: ENV['PGHOST'], port: ENV['PGPORT'].to_i, dbname: ENV['PGDATABASE'], user: ENV['PGUSER'], password: ENV['PGPASSWORD']);" && exit 0 + pg_isready -h "$PGHOST" -p "$PGPORT" -d "$PGDATABASE" && break sleep 2 done - exit 1 + bundle exec ruby -e "require 'pg'; PG.connect(host: ENV['PGHOST'], port: ENV['PGPORT'].to_i, dbname: ENV['PGDATABASE'], user: ENV['PGUSER'], password: ENV['PGPASSWORD']);" - name: Setup database run: bundle exec rake db:create db:migrate db:seed From c9a00f7bfcc7f647b52963e3c14c15dec2f9d94a Mon Sep 17 00:00:00 2001 From: Viachaslau Tyshkavets Date: Fri, 9 Jan 2026 13:09:13 +0400 Subject: [PATCH 7/9] chore: missing dir fix --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad775c3..1470567 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,13 +89,13 @@ jobs: - name: Start server run: | - bundle exec rails server -b 0.0.0.0 -p 3000 >tmp/rails.log 2>&1 & + bundle exec rails server -b 0.0.0.0 -p 3000 >rails.log 2>&1 & for i in $(seq 1 30); do curl -sSf http://localhost:3000 >/dev/null && exit 0 sleep 2 done echo "Server failed to start" - tail -n 200 tmp/rails.log + tail -n 200 rails.log exit 1 - name: Check homepage From b0d4d4999426454d93a8f124163753500d201ad4 Mon Sep 17 00:00:00 2001 From: Viachaslau Tyshkavets Date: Fri, 9 Jan 2026 13:35:12 +0400 Subject: [PATCH 8/9] chore: server readiness check improvements --- .github/workflows/ci.yml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1470567..e3d09bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,13 +90,26 @@ jobs: - name: Start server run: | bundle exec rails server -b 0.0.0.0 -p 3000 >rails.log 2>&1 & + + - name: Wait for server readiness + run: | + READY=0 for i in $(seq 1 30); do - curl -sSf http://localhost:3000 >/dev/null && exit 0 + if curl -sSf http://localhost:3000 >/dev/null; then + READY=1 + break + fi sleep 2 done - echo "Server failed to start" - tail -n 200 rails.log - exit 1 + if [ "$READY" -ne 1 ]; then + echo "Server failed to start" + tail -n 200 rails.log || true + exit 1 + fi - name: Check homepage - run: curl -sSf http://localhost:3000 | grep -F "Home" + run: | + if ! curl -sSf http://localhost:3000 | grep -F "Home"; then + echo "Homepage check failed" + exit 1 + fi From 020eb38938b0c2dccff8154f207491d533553c7b Mon Sep 17 00:00:00 2001 From: Viachaslau Tyshkavets Date: Fri, 9 Jan 2026 14:07:15 +0400 Subject: [PATCH 9/9] chore: following redirects on server probes --- .github/workflows/ci.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3d09bb..720a590 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,10 +95,13 @@ jobs: run: | READY=0 for i in $(seq 1 30); do - if curl -sSf http://localhost:3000 >/dev/null; then + echo "Attempt ${i}/30: checking http://localhost:3000" + if curl -sSfL http://localhost:3000 >/dev/null; then + echo "Server responded successfully on attempt ${i}." READY=1 break fi + echo "Server still starting up, waiting 2s before retry." sleep 2 done if [ "$READY" -ne 1 ]; then @@ -106,10 +109,12 @@ jobs: tail -n 200 rails.log || true exit 1 fi + echo "Server is ready; last 200 lines of rails.log:" + tail -n 200 rails.log || true - name: Check homepage run: | - if ! curl -sSf http://localhost:3000 | grep -F "Home"; then + if ! curl -sSfL http://localhost:3000 | grep -F "Home"; then echo "Homepage check failed" exit 1 - fi + fi \ No newline at end of file