Skip to content

Commit 66fdfeb

Browse files
authored
Merge pull request #1 from Intellection/dockerize
Package Gemstash for Docker
2 parents 474a120 + a0c43d7 commit 66fdfeb

12 files changed

Lines changed: 323 additions & 2 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
## 1.1.0
4+
5+
* Package gemstash v1.1.0.
6+
* Install system libraries for all database drivers i.e. postgresql, mysql2.
7+
* Define Ruby dependencies via `Gemfile.lock`.
8+
* Run gemstash as `gemstash` user instead of `root`.
9+
* Add dynamic configuration with MySQL, PostgreSQL and SQLite support.

CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* @itskingori
2+
* @zacblazic

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM ruby:2.4.1-alpine
2+
3+
# Install system dependencies
4+
RUN apk --update add \
5+
build-base \
6+
mariadb-dev \
7+
postgresql-dev \
8+
sqlite-dev \
9+
su-exec \
10+
tini && \
11+
gem update --system && \
12+
gem update bundler && \
13+
rm -rf /var/cache/apk/*
14+
15+
# Create gemstash user
16+
ENV GEMSTASH_USER="gemstash"
17+
ENV GEMSTASH_HOME="/home/${GEMSTASH_USER}"
18+
RUN addgroup -g "9999" "${GEMSTASH_USER}" && \
19+
adduser -S -D -u "9999" -G "${GEMSTASH_USER}" "${GEMSTASH_USER}"
20+
21+
# Install Gemstash
22+
RUN mkdir -p "${GEMSTASH_HOME}/app"
23+
WORKDIR "${GEMSTASH_HOME}/app"
24+
COPY "app/" "${GEMSTASH_HOME}/app"
25+
RUN bundle config disable_checksum_validation true && \
26+
bundle install --jobs 4 --retry 3
27+
28+
VOLUME "${GEMSTASH_HOME}/data"
29+
30+
EXPOSE 9292
31+
COPY entrypoint.sh /
32+
ENTRYPOINT ["/entrypoint.sh"]
33+
CMD ["bundle", "exec", "gemstash", "start", "--no-daemonize"]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 Intellection Software Ltd
3+
Copyright (c) 2017 ZappiStore Ltd
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,45 @@
11
# docker-gemstash
2-
A RubyGems.org cache and private gem server
2+
3+
A RubyGems.org cache and private gem server.
4+
5+
## Usage
6+
7+
### Basic
8+
9+
```
10+
$ docker run \
11+
--publish=9292:9292 \
12+
zappi/gemstash:<VERSION>
13+
```
14+
15+
### Advanced
16+
17+
#### MySQL
18+
19+
See `docker-compose.mysql.yml` for an example of how to use MySQL. To run:
20+
21+
```
22+
$ export COMPOSE_FILE="docker-compose.mysql.yml"
23+
$ docker-compose up -d
24+
25+
$ docker-compose ps
26+
Name Command State Ports
27+
-------------------------------------------------------------------------------------------
28+
dockergemstash_gemstash_1 /entrypoint.sh gemstash st ... Up 0.0.0.0:9292->9292/tcp
29+
dockergemstash_mysql_1 docker-entrypoint.sh mysqld Up 3306/tcp
30+
```
31+
32+
#### PostgreSQL
33+
34+
See `docker-compose.postgres.yml` for an example of how to use PostgreSQL. To run:
35+
36+
```
37+
$ export COMPOSE_FILE="docker-compose.postgres.yml"
38+
$ docker-compose up -d
39+
40+
$ docker-compose ps
41+
Name Command State Ports
42+
-------------------------------------------------------------------------------------------
43+
dockergemstash_gemstash_1 /entrypoint.sh gemstash st ... Up 0.0.0.0:9292->9292/tcp
44+
dockergemstash_postgres_1 docker-entrypoint.sh postgres Up 5432/tcp
45+
```

app/Gemfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source 'https://rubygems.org'
2+
3+
ruby '2.4.1'
4+
5+
# A simple, fast Mysql library for Ruby, binding to libmysql.
6+
gem 'mysql2', '~> 0.4.8'
7+
8+
# Pg is the Ruby interface to the PostgreSQL.
9+
gem 'pg', '~> 0.21.0'
10+
11+
# Gemstash acts as a local RubyGems server, caching copies of gems from
12+
# RubyGems.org automatically, and eventually letting you push your own private
13+
# gems as well.
14+
gem 'gemstash', '1.1.0'

app/Gemfile.lock

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
activesupport (5.1.2)
5+
concurrent-ruby (~> 1.0, >= 1.0.2)
6+
i18n (~> 0.7)
7+
minitest (~> 5.1)
8+
tzinfo (~> 1.1)
9+
concurrent-ruby (1.0.5)
10+
dalli (2.7.6)
11+
faraday (0.12.2)
12+
multipart-post (>= 1.2, < 3)
13+
faraday_middleware (0.12.1)
14+
faraday (>= 0.7.4, < 1.0)
15+
gemstash (1.1.0)
16+
activesupport (>= 4.2, < 6)
17+
dalli (~> 2.7)
18+
faraday (~> 0.9)
19+
faraday_middleware (~> 0.10)
20+
lru_redux (~> 1.1)
21+
puma (~> 2.14)
22+
sequel (~> 4.26)
23+
server_health_check-rack (~> 0.1)
24+
sinatra (~> 1.4)
25+
sqlite3 (~> 1.3)
26+
thor (~> 0.19)
27+
i18n (0.8.6)
28+
lru_redux (1.1.0)
29+
minitest (5.10.3)
30+
multipart-post (2.0.0)
31+
mysql2 (0.4.8)
32+
pg (0.21.0)
33+
puma (2.16.0)
34+
rack (1.6.8)
35+
rack-protection (1.5.3)
36+
rack
37+
sequel (4.49.0)
38+
server_health_check (1.0.2)
39+
server_health_check-rack (0.1.0)
40+
server_health_check (~> 1.0, >= 1.0.1)
41+
sinatra (1.4.8)
42+
rack (~> 1.5)
43+
rack-protection (~> 1.4)
44+
tilt (>= 1.3, < 3)
45+
sqlite3 (1.3.13)
46+
thor (0.19.4)
47+
thread_safe (0.3.6)
48+
tilt (2.0.8)
49+
tzinfo (1.2.3)
50+
thread_safe (~> 0.1)
51+
52+
PLATFORMS
53+
ruby
54+
55+
DEPENDENCIES
56+
gemstash (= 1.1.0)
57+
mysql2 (~> 0.4.8)
58+
pg (~> 0.21.0)
59+
60+
RUBY VERSION
61+
ruby 2.4.1p111
62+
63+
BUNDLED WITH
64+
1.15.3

app/config.yml.erb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
:base_path: <%= "#{ENV['GEMSTASH_HOME']}/data" %>
2+
:cache_type: memory
3+
:rubygems_url: https://rubygems.org
4+
:puma_threads: <%= ENV['GEMSTASH_PUMA_THREADS'].to_i %>
5+
:bind: tcp://0.0.0.0:9292
6+
:protected_fetch: false
7+
:fetch_timeout: 20
8+
:log_file: :stdout
9+
10+
<% if ENV['GEMSTASH_DB_ADAPTER'] == 'mysql2' %>
11+
# mysql2 adapter
12+
:db_adapter: mysql2
13+
:db_url: <%= "mysql2://#{ENV['GEMSTASH_DB_HOST']}:#{ENV['GEMSTASH_DB_PORT']}/#{ENV['GEMSTASH_DB_DATABASE']}" %>
14+
:db_connection_options:
15+
:adapter: 'mysql2'
16+
:user: <%= ENV['GEMSTASH_DB_USERNAME'] %>
17+
:password: <%= ENV['GEMSTASH_DB_PASSWORD'] %>
18+
:max_connections: <%= ENV['GEMSTASH_PUMA_THREADS'].to_i + 1 %>
19+
<% elsif ENV['GEMSTASH_DB_ADAPTER'] == 'postgres' %>
20+
# postgres adapter
21+
:db_adapter: postgres
22+
:db_url: <%= "postgres://#{ENV['GEMSTASH_DB_HOST']}:#{ENV['GEMSTASH_DB_PORT']}/#{ENV['GEMSTASH_DB_DATABASE']}" %>
23+
:db_connection_options:
24+
:adapter: 'postgres'
25+
:user: <%= ENV['GEMSTASH_DB_USERNAME'] %>
26+
:password: <%= ENV['GEMSTASH_DB_PASSWORD'] %>
27+
:max_connections: <%= ENV['GEMSTASH_PUMA_THREADS'].to_i + 1 %>
28+
:connect_timeout: 10
29+
:read_timeout: 5
30+
:timeout: 30
31+
<% else %>
32+
# sqlite adapter (default)
33+
:db_adapter: sqlite3
34+
:db_url: sqlite://gemstash.db
35+
<% end %>

docker-compose.mysql.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
version: '2.1'
3+
services:
4+
gemstash:
5+
image: zappi/gemstash:1.1.0
6+
environment:
7+
RACK_ENV: production
8+
GEMSTASH_DB_ADAPTER: mysql2
9+
GEMSTASH_DB_USERNAME: root
10+
GEMSTASH_DB_PASSWORD: sekretpassword
11+
GEMSTASH_DB_DATABASE: gemstash
12+
GEMSTASH_DB_HOST: mysql
13+
GEMSTASH_DB_PORT: 3306
14+
GEMSTASH_PUMA_THREADS: 4
15+
ports:
16+
- 9292:9292
17+
volumes:
18+
- gemstash_data:/home/gemstash/data
19+
links:
20+
- mysql
21+
depends_on:
22+
mysql:
23+
condition: service_healthy
24+
mysql:
25+
image: mysql:5.7.19
26+
volumes:
27+
- mysql_data:/var/lib/mysql
28+
expose:
29+
- 3306
30+
environment:
31+
- MYSQL_ROOT_PASSWORD=sekretpassword
32+
- MYSQL_DATABASE=gemstash
33+
healthcheck:
34+
test:
35+
- CMD
36+
- mysql
37+
- --user=root
38+
- --password=sekretpassword
39+
- --execute=select 1
40+
- --host=127.0.0.1
41+
- --port=3306
42+
- gemstash
43+
interval: 1s
44+
retries: 60
45+
46+
volumes:
47+
gemstash_data:
48+
driver: local
49+
mysql_data:
50+
driver: local

docker-compose.postgres.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
version: '2.1'
3+
services:
4+
gemstash:
5+
image: zappi/gemstash:1.1.0
6+
environment:
7+
RACK_ENV: production
8+
GEMSTASH_DB_ADAPTER: postgres
9+
GEMSTASH_DB_USERNAME: postgres
10+
GEMSTASH_DB_PASSWORD: sekretpassword
11+
GEMSTASH_DB_DATABASE: gemstash
12+
GEMSTASH_DB_HOST: postgres
13+
GEMSTASH_DB_PORT: 5432
14+
GEMSTASH_PUMA_THREADS: 4
15+
ports:
16+
- 9292:9292
17+
volumes:
18+
- gemstash_data:/home/gemstash/data
19+
links:
20+
- postgres
21+
postgres:
22+
image: postgres:9.6.3-alpine
23+
volumes:
24+
- postgres_data:/var/lib/mysql
25+
expose:
26+
- 5432
27+
environment:
28+
- POSTGRES_PASSWORD=sekretpassword
29+
- POSTGRES_DB=gemstash
30+
31+
volumes:
32+
gemstash_data:
33+
driver: local
34+
postgres_data:
35+
driver: local

0 commit comments

Comments
 (0)