Skip to content

Commit

Permalink
Upgrade ruby and migrate to Github actions (#7)
Browse files Browse the repository at this point in the history
* Upgrade ruby from 2.3 to 2.7
* Add GH action to run tests & publish to Coveralls
* Remove support for ruby 2.4
* Add GH action to release to rubygems
* Fix dependency versioning
* Add GH action to build/push docker image
* Rename docker repo prefix after moving to GH
  • Loading branch information
hammady committed Sep 15, 2023
1 parent 31aa48c commit bda95f5
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 59 deletions.
25 changes: 25 additions & 0 deletions .github/actions/rspec_tests/action.yml
@@ -0,0 +1,25 @@
name: rspec-tests
description: Composite action for rspec tests
inputs:
github-token:
required: true
runs:
using: composite
steps:
- name: Install bundler
shell: bash
# The bundler version used must match the one in the repo's gemspec
run: gem install bundler:2.2.19
- name: Bundle dependencies
shell: bash
run: bundle
- name: Run rspec tests
shell: bash
env:
CI: true
run: bundle exec rspec
- name: Use coveralls
uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ inputs.github-token }}
path-to-lcov: 'coverage/lcov.info'
62 changes: 62 additions & 0 deletions .github/workflows/docker-build-push.yml
@@ -0,0 +1,62 @@
name: Docker

on:
push:
branches:
- master
tags:
- v*

env:
IMAGE_NAME: hammady/scaltainer

jobs:
docker:
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Determine target image name
id: image-name
run: |
IMAGE_ID=ghcr.io/$IMAGE_NAME
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
IMAGES=
IMAGES="$IMAGE_ID:$VERSION"$'\n'$IMAGES
# debug output
echo images $IMAGES
echo ::set-output name=images::"$IMAGES"
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ steps.image-name.outputs.images }}
25 changes: 25 additions & 0 deletions .github/workflows/rubygems-release.yml
@@ -0,0 +1,25 @@
name: Release
on:
push:
tags:
- v*
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7'
- name: Install bundler
shell: bash
# The bundler version used must match the one in the repo's gemspec
run: gem install bundler:2.2.19
- name: Bundle dependencies
shell: bash
run: bundle
- name: Release gem
shell: bash
env:
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: ./publish.sh
24 changes: 24 additions & 0 deletions .github/workflows/tests.yml
@@ -0,0 +1,24 @@
name: 'Test'
on:
push:
branches:
- master
tags:
- v*
pull_request:
types: [opened, reopened, edited, synchronize]
jobs:
test:
strategy:
matrix:
ruby_version: [2.5, 2.6, 2.7]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '${{ matrix.ruby_version }}'
- name: Run rspec tests
uses: ./.github/actions/rspec_tests
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions Dockerfile
@@ -1,6 +1,6 @@
FROM ruby:2.3
FROM ruby:2.7

label maintainer="Hossam Hammady <github@hammady.net>"
LABEL maintainer="Hossam Hammady <github@hammady.net>"

ENV NEW_RELIC_LOG=stdout
ENV NEW_RELIC_AUTOSTART_DENYLISTED_CONSTANTS=Scaltainer
Expand Down
42 changes: 17 additions & 25 deletions Gemfile.lock
@@ -1,28 +1,22 @@
PATH
remote: .
specs:
scaltainer (0.5.0)
docker-api
dotenv
excon (>= 0.47.0)
kubeclient
newrelic_rpm
prometheus-client
scaltainer (0.6.0)
docker-api (~> 2.1)
dotenv (~> 2.7)
excon (~> 0.47)
kubeclient (~> 4.9)
newrelic_rpm (~> 7.1)
prometheus-client (~> 2.1)

GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
coderay (1.1.1)
coveralls (0.8.21)
json (>= 1.8, < 3)
simplecov (~> 0.14.1)
term-ansicolor (~> 1.3)
thor (~> 0.19.4)
tins (~> 1.6)
diff-lcs (1.3)
docile (1.1.5)
docile (1.4.0)
docker-api (2.1.0)
excon (>= 0.47.0)
multi_json
Expand All @@ -45,7 +39,7 @@ GEM
http-form_data (2.3.0)
http-parser (1.2.3)
ffi-compiler (>= 1.0, < 2.0)
json (2.3.1)
json (2.6.3)
jsonpath (1.0.5)
multi_json
to_regexp (~> 0.2.1)
Expand Down Expand Up @@ -82,15 +76,12 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
simplecov (0.14.1)
docile (~> 1.1.0)
simplecov (0.17.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
term-ansicolor (1.6.0)
tins (~> 1.0)
thor (0.19.4)
tins (1.13.2)
simplecov-html (0.10.2)
simplecov-lcov (0.7.0)
to_regexp (0.2.1)
unf (0.1.4)
unf_ext
Expand All @@ -100,12 +91,13 @@ PLATFORMS
ruby

DEPENDENCIES
bundler (>= 2.2.10)
bundler (~> 2.2)
coderay (~> 1.1)
coveralls (~> 0.8)
rake (>= 12.3.3)
rake (~> 13.0)
rspec (~> 3.5)
scaltainer!
simplecov (~> 0.17)
simplecov-lcov (~> 0.7)

BUNDLED WITH
2.2.19
6 changes: 3 additions & 3 deletions README.md
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/hammady/scaltainer.svg?branch=master)](https://travis-ci.org/hammady/scaltainer)
![Build Status](https://github.com/hammady/scaltainer/actions/workflows/tests.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/hammady/scaltainer/badge.svg?service=github&branch=master)](https://coveralls.io/github/hammady/scaltainer?branch=master)
[![Gem Version](https://badge.fury.io/rb/scaltainer.svg)](https://badge.fury.io/rb/scaltainer)

Expand Down Expand Up @@ -213,7 +213,7 @@ A service definition for scaltainer is typically something like this:
version: '3.3'
services:
scaltainer:
image: rayyanqcri/scaltainer:latest
image: hammady/scaltainer:latest
command: -f /scaltainer.yml --state-file /tmp/scaltainer-state.yml -w 60
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Expand Down Expand Up @@ -282,7 +282,7 @@ Where scaltainer-kube.yaml has the following content:
app: scaltainer
spec:
containers:
- image: rayyanqcri/scaltainer:latest
- image: hammady/scaltainer:latest
name: scaltainer
args:
- -o
Expand Down
2 changes: 1 addition & 1 deletion lib/scaltainer/version.rb
@@ -1,3 +1,3 @@
module Scaltainer
VERSION = "0.5.0"
VERSION = "0.6.0"
end
10 changes: 10 additions & 0 deletions publish.sh
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
if [ ! -z "$RUBYGEMS_API_KEY" ]; then
mkdir $HOME/.gem
creds="$HOME/.gem/credentials"
echo -e "---\n:rubygems_api_key: $RUBYGEMS_API_KEY" > $creds
chmod 0600 $creds
fi

gem build scaltainer.gemspec
gem push scaltainer*.gem
23 changes: 12 additions & 11 deletions scaltainer.gemspec
Expand Up @@ -22,16 +22,17 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", ">= 2.2.10"
spec.add_development_dependency "rake", ">= 12.3.3"
spec.add_development_dependency 'rspec', '~> 3.5'
spec.add_development_dependency 'coderay', '~> 1.1'
spec.add_development_dependency 'coveralls', '~> 0.8'
spec.add_development_dependency "bundler", "~> 2.2"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.5"
spec.add_development_dependency "coderay", "~> 1.1"
spec.add_development_dependency "simplecov", "~> 0.17"
spec.add_development_dependency "simplecov-lcov", "~> 0.7"

spec.add_runtime_dependency 'excon', '>= 0.47.0'
spec.add_runtime_dependency "docker-api"
spec.add_runtime_dependency "kubeclient"
spec.add_runtime_dependency "dotenv"
spec.add_runtime_dependency "prometheus-client"
spec.add_runtime_dependency "newrelic_rpm"
spec.add_runtime_dependency "excon", "~> 0.47"
spec.add_runtime_dependency "docker-api", "~> 2.1"
spec.add_runtime_dependency "kubeclient", "~> 4.9"
spec.add_runtime_dependency "dotenv", "~> 2.7"
spec.add_runtime_dependency "prometheus-client", "~> 2.1"
spec.add_runtime_dependency "newrelic_rpm", "~> 7.1"
end
26 changes: 18 additions & 8 deletions spec/spec_helper.rb
Expand Up @@ -15,14 +15,24 @@
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration

require 'simplecov'
require 'coveralls'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new [
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]

SimpleCov.start
require 'simplecov-lcov'

SimpleCov.start do
if ENV['CI']
SimpleCov::Formatter::LcovFormatter.config do |config|
config.report_with_single_file = true
config.single_report_path = 'coverage/lcov.info'
end

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new [
SimpleCov::Formatter::LcovFormatter
]
else
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new [
SimpleCov::Formatter::HTMLFormatter
]
end
end

require 'scaltainer'

Expand Down

0 comments on commit bda95f5

Please sign in to comment.