Skip to content

Commit b2c3bbc

Browse files
committed
Moving from docker to podman/Containerfile etc
Signed-off-by: David Kirwan <davidkirwanirl@gmail.com>
1 parent d816727 commit b2c3bbc

7 files changed

Lines changed: 179 additions & 160 deletions

File tree

.github/workflows/ci.yml

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
bundle exec brakeman --no-pager
7474
7575
build:
76-
name: Build Docker Image
76+
name: Build Podman Image
7777
runs-on: ubuntu-latest
7878
needs: [test, security]
7979
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
@@ -82,37 +82,35 @@ jobs:
8282
- name: Checkout code
8383
uses: actions/checkout@v4
8484

85-
- name: Set up Docker Buildx
86-
uses: docker/setup-buildx-action@v3
85+
- name: Install Podman
86+
run: |
87+
sudo apt-get update
88+
sudo apt-get install -y podman qemu-user-static
89+
90+
- name: Log in to container registry
91+
env:
92+
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}
93+
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
94+
run: echo "$QUAY_TOKEN" | podman login quay.io -u "$QUAY_USERNAME" --password-stdin
95+
96+
- name: Build and push container image
97+
env:
98+
IMAGE: quay.io/dkirwan/asset_monitoring
99+
run: |
100+
set -euo pipefail
87101
88-
- name: Login to Container Registry
89-
uses: docker/login-action@v3
90-
with:
91-
registry: quay.io
92-
username: ${{ secrets.QUAY_USERNAME }}
93-
password: ${{ secrets.QUAY_TOKEN }}
102+
podman manifest rm "${IMAGE}:manifest" 2>/dev/null || true
103+
podman manifest create "${IMAGE}:manifest"
94104
95-
- name: Extract metadata
96-
id: meta
97-
uses: docker/metadata-action@v5
98-
with:
99-
images: quay.io/dkirwan/asset_monitoring
100-
tags: |
101-
type=ref,event=branch
102-
type=ref,event=pr
103-
type=sha,prefix={{branch}}-
104-
type=raw,value=latest,enable={{is_default_branch}}
105-
106-
- name: Build and push Docker image
107-
uses: docker/build-push-action@v5
108-
with:
109-
context: .
110-
platforms: linux/amd64,linux/arm64
111-
push: true
112-
tags: ${{ steps.meta.outputs.tags }}
113-
labels: ${{ steps.meta.outputs.labels }}
114-
cache-from: type=gha
115-
cache-to: type=gha,mode=max
105+
for platform in linux/amd64 linux/arm64; do
106+
arch="${platform#linux/}"
107+
podman build --platform "${platform}" -t "${IMAGE}:build-${arch}" -f Containerfile .
108+
podman manifest add "${IMAGE}:manifest" "${IMAGE}:build-${arch}"
109+
done
110+
111+
for tag in "${GITHUB_SHA}" latest "${GITHUB_REF_NAME}"; do
112+
podman manifest push "${IMAGE}:manifest" "${IMAGE}:${tag}"
113+
done
116114
117115
deploy:
118116
name: Deploy to Kubernetes

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ Thumbs.db
3939
/.bundle/
4040
/vendor/bundle/
4141

42-
# Docker
43-
.dockerignore
42+
# Podman
43+
.containerignore
File renamed without changes.

Makefile

Lines changed: 38 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,69 @@
11
# Makefile for asset-monitoring
22
#
3-
# This provides the same functionality as the Rakefile.
4-
# Run `make` or `make help` to see available commands.
3+
# Mirrors the Rakefile. Run `make` or `make help` to see available commands.
54

65
SHELL := /bin/bash
76
.SHELLFLAGS := -eu -o pipefail -c
87

9-
.PHONY: help spec rubocop check coverage install server dev console \
10-
docker_build docker_run docker-build docker-run test lint
8+
APP_HOST ?= 0.0.0.0
9+
APP_PORT ?= 8080
10+
CONTAINERFILE ?= Containerfile
11+
IMAGE ?= asset-monitoring:latest
12+
BUNDLE ?= bundle
13+
BUNDLE_EXEC ?= $(BUNDLE) exec
14+
RACKUP := $(BUNDLE_EXEC) rackup config.ru --host $(APP_HOST) -p $(APP_PORT)
1115

12-
.DEFAULT_GOAL := help
16+
.PHONY: help install server dev console \
17+
spec test rubocop lint check coverage \
18+
security audit brakeman \
19+
podman-build podman-run podman_build podman_run
1320

14-
##@ General
21+
.DEFAULT_GOAL := help
1522

1623
help: ## Display available commands
17-
@echo 'Asset Monitoring - Available Commands'
18-
@echo '======================================'
19-
@echo ''
20-
@echo 'Setup:'
21-
@echo ' make install - Install dependencies via Bundler'
22-
@echo ''
23-
@echo 'Development:'
24-
@echo ' make server - Start the application server on 0.0.0.0:8080'
25-
@echo ' make dev - Start with auto-reload (requires rerun gem)'
26-
@echo ' make console - Start an interactive console'
27-
@echo ''
28-
@echo 'Testing:'
29-
@echo ' make spec - Run RSpec tests'
30-
@echo ' make rubocop - Run RuboCop linter'
31-
@echo ' make check - Run all checks (rubocop + specs)'
32-
@echo ' make coverage - Run tests with coverage report'
33-
@echo ' make test - Alias for spec'
34-
@echo ' make lint - Alias for rubocop'
35-
@echo ''
36-
@echo 'Docker:'
37-
@echo ' make docker_build - Build the Docker image'
38-
@echo ' make docker_run - Run the Docker container'
39-
@echo ' make docker-build - Alias for docker_build'
40-
@echo ' make docker-run - Alias for docker_run'
41-
@echo ''
42-
@echo 'Web UI (open in a browser, server on 0.0.0.0:8080):'
43-
@echo ' / - Redirects to /dashboard'
44-
@echo ' /dashboard - Price charts (BullionVault + Coinbase; one point per background scrape). Retention configurable via PRICE_HISTORY_RETENTION_DAYS.'
45-
@echo ''
46-
@echo 'API / metrics (curl or similar):'
47-
@echo ' /api/price_history.json - JSON time series for the dashboard (same underlying data as /metrics, parsed). Includes retention_days.'
48-
@echo ' /metrics - Prometheus text exposition (cached from last successful scrape)'
49-
@echo ' /health - Liveness JSON probe'
50-
@echo ' /ready - Readiness JSON probe'
51-
@echo ''
52-
@echo 'Optional SQLite persistence (survives restarts):'
53-
@echo ' Set PRICE_HISTORY_DB_PATH and (optionally) PRICE_HISTORY_RETENTION_DAYS.'
54-
@echo ' See README.asciidoc for Kubernetes PVC + replica considerations.'
55-
@echo ''
56-
57-
##@ Setup
24+
@cat tasks/help.txt
5825

5926
install: ## Install dependencies via Bundler
60-
bundle install
61-
62-
##@ Development
27+
$(BUNDLE) install
6328

64-
server: ## Start the application server on 0.0.0.0:8080
65-
bundle exec rackup --host 0.0.0.0 -p 8080
29+
server: ## Start the application server
30+
$(RACKUP)
6631

6732
dev: ## Start the application server with auto-reload (development)
68-
bundle exec rerun -- rackup --host 0.0.0.0 -p 8080
33+
$(BUNDLE_EXEC) rerun -- $(RACKUP)
6934

7035
console: ## Start an interactive Pry console with the app loaded
71-
bundle exec ruby -Ilib -r asset_monitoring -r pry -e 'Pry.start'
72-
73-
##@ Testing
36+
METRICS_SCHEDULER_DISABLED=1 $(BUNDLE_EXEC) pry -Ilib -r asset_monitoring
7437

7538
spec: ## Run RSpec tests
76-
bundle exec rspec
39+
$(BUNDLE_EXEC) rspec
40+
41+
test: spec ## Alias for spec
7742

7843
rubocop: ## Run RuboCop linter
79-
bundle exec rubocop
44+
$(BUNDLE_EXEC) rubocop
45+
46+
lint: rubocop ## Alias for rubocop
8047

8148
check: rubocop spec ## Run all checks (rubocop + specs)
8249

83-
coverage: ## Run tests with coverage (SimpleCov)
84-
COVERAGE=true bundle exec rspec
50+
coverage: ## Run tests with coverage report
51+
COVERAGE=true $(BUNDLE_EXEC) rspec
8552

86-
test: spec ## Alias for spec
53+
audit: ## Run Bundler audit
54+
$(BUNDLE_EXEC) bundle-audit check --update
8755

88-
lint: rubocop ## Alias for rubocop
56+
brakeman: ## Run Brakeman
57+
$(BUNDLE_EXEC) brakeman --no-pager
8958

90-
##@ Docker
59+
security: audit brakeman ## Run security checks (bundle-audit + brakeman)
9160

92-
docker_build: ## Build the Docker image tagged asset-monitoring:latest
93-
docker build -t asset-monitoring:latest .
61+
podman-build: ## Build the container image tagged asset-monitoring:latest
62+
podman build -t $(IMAGE) -f $(CONTAINERFILE) .
9463

95-
docker_run: ## Run the Docker container (port 8080)
96-
docker run -p 8080:8080 asset-monitoring:latest
64+
podman-run: ## Run the container (port $(APP_PORT))
65+
podman run -p $(APP_PORT):$(APP_PORT) $(IMAGE)
9766

98-
docker-build: docker_build ## Alias for docker_build
67+
podman_build: podman-build ## Alias for podman-build
9968

100-
docker-run: docker_run ## Alias for docker_run
69+
podman_run: podman-run ## Alias for podman-run

Rakefile

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,88 +5,94 @@ require 'bundler/setup'
55
require 'rspec/core/rake_task'
66
require 'rubocop/rake_task'
77

8+
APP_HOST = ENV.fetch('HOST', '0.0.0.0')
9+
APP_PORT = ENV.fetch('PORT', '8080')
10+
CONTAINERFILE = 'Containerfile'
11+
IMAGE = 'asset-monitoring:latest'
12+
RACKUP_CMD = "bundle exec rackup config.ru --host #{APP_HOST} -p #{APP_PORT}"
13+
814
RSpec::Core::RakeTask.new(:spec)
915
RuboCop::RakeTask.new(:rubocop)
1016

17+
desc 'Run RSpec tests'
18+
task test: :spec
19+
20+
desc 'Run RuboCop linter'
21+
task lint: :rubocop
22+
1123
desc 'Run all checks (rubocop + specs)'
1224
task check: %i[rubocop spec]
1325

14-
desc 'Run tests with coverage'
26+
desc 'Run tests with coverage report'
1527
task :coverage do
1628
ENV['COVERAGE'] = 'true'
29+
Rake::Task['spec'].reenable
1730
Rake::Task['spec'].invoke
1831
end
1932

33+
namespace :security do
34+
desc 'Run Bundler audit'
35+
task :audit do
36+
sh 'bundle exec bundle-audit check --update'
37+
end
38+
39+
desc 'Run Brakeman'
40+
task :brakeman do
41+
sh 'bundle exec brakeman --no-pager'
42+
end
43+
end
44+
45+
desc 'Run security checks (bundle-audit + brakeman)'
46+
task security: %w[security:audit security:brakeman]
47+
48+
desc 'Run Bundler audit'
49+
task audit: 'security:audit'
50+
51+
desc 'Run Brakeman'
52+
task brakeman: 'security:brakeman'
53+
2054
desc 'Install dependencies'
2155
task :install do
2256
sh 'bundle install'
2357
end
2458

2559
desc 'Start the application server'
2660
task :server do
27-
sh 'bundle exec rackup --host 0.0.0.0 -p 8080'
61+
sh RACKUP_CMD
2862
end
2963

3064
desc 'Start the application server with auto-reload (development)'
3165
task :dev do
32-
sh 'bundle exec rerun -- rackup --host 0.0.0.0 -p 8080'
66+
sh "bundle exec rerun -- #{RACKUP_CMD}"
3367
end
3468

35-
desc 'Build the Docker image'
36-
task :docker_build do
37-
sh 'docker build -t asset-monitoring:latest .'
69+
desc 'Start an interactive console'
70+
task :console do
71+
ENV['METRICS_SCHEDULER_DISABLED'] = '1'
72+
sh 'bundle exec pry -Ilib -r asset_monitoring'
3873
end
3974

40-
desc 'Run the Docker container'
41-
task :docker_run do
42-
sh 'docker run -p 8080:8080 asset-monitoring:latest'
75+
namespace :podman do
76+
desc 'Build the container image'
77+
task :build do
78+
sh "podman build -t #{IMAGE} -f #{CONTAINERFILE} ."
79+
end
80+
81+
desc 'Run the container'
82+
task :run do
83+
sh "podman run -p #{APP_PORT}:#{APP_PORT} #{IMAGE}"
84+
end
4385
end
4486

87+
desc 'Build the container image (alias for podman:build)'
88+
task podman_build: 'podman:build'
89+
90+
desc 'Run the container (alias for podman:run)'
91+
task podman_run: 'podman:run'
92+
4593
desc 'Display available commands'
46-
task :default do
47-
puts <<~HELP
48-
Asset Monitoring - Available Commands
49-
======================================
50-
51-
Setup:
52-
rake install - Install dependencies via Bundler
53-
54-
Development:
55-
rake server - Start the application server on 0.0.0.0:8080
56-
rake dev - Start with auto-reload (requires rerun gem)
57-
rake console - Start an interactive console
58-
59-
Testing:
60-
rake spec - Run RSpec tests
61-
rake rubocop - Run RuboCop linter
62-
rake check - Run all checks (rubocop + specs)
63-
rake coverage - Run tests with coverage report
64-
65-
Docker:
66-
rake docker_build - Build the Docker image
67-
rake docker_run - Run the Docker container
68-
69-
Web UI (open in a browser, server on 0.0.0.0:8080):
70-
/ - Redirects to /dashboard
71-
/dashboard - Price charts (BullionVault + Coinbase; one point per background scrape). Retention configurable via PRICE_HISTORY_RETENTION_DAYS.
72-
73-
API / metrics (curl or similar):
74-
/api/price_history.json - JSON time series for the dashboard (same underlying data as /metrics, parsed). Includes retention_days.
75-
/metrics - Prometheus text exposition (cached from last successful scrape)
76-
/health - Liveness JSON probe
77-
/ready - Readiness JSON probe
78-
79-
Optional SQLite persistence (survives restarts):
80-
Set PRICE_HISTORY_DB_PATH and (optionally) PRICE_HISTORY_RETENTION_DAYS.
81-
See README.asciidoc for Kubernetes PVC + replica considerations.
82-
83-
HELP
94+
task :help do
95+
puts File.read(File.expand_path('tasks/help.txt', __dir__))
8496
end
8597

86-
desc 'Start an interactive console'
87-
task :console do
88-
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
89-
require 'asset_monitoring'
90-
require 'pry'
91-
Pry.start
92-
end
98+
task default: :help

spec/spec_helper.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
66

7-
require 'simplecov'
8-
SimpleCov.start do
9-
add_filter '/spec/'
10-
add_filter '/vendor/'
11-
minimum_coverage 80
7+
if ENV['COVERAGE'] == 'true' || ENV['CI']
8+
require 'simplecov'
9+
SimpleCov.start do
10+
add_filter '/spec/'
11+
add_filter '/vendor/'
12+
minimum_coverage 80
13+
end
1214
end
1315

1416
require 'rspec'

0 commit comments

Comments
 (0)