pinject 0.1.1 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +43 -0
- data/.github/workflows/ruby.yml +31 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +58 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +8 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/exe/pinject +6 -0
- data/lib/pinject/docker.rb +146 -0
- data/lib/pinject/version.rb +5 -0
- data/lib/pinject.rb +15 -0
- data/pinject.gemspec +26 -0
- data/sig/pinject.rbs +4 -0
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b9e9f711a85a5ed50b33b9c493c96331ba3ffeaa0df0a44ef488514f753ca2d
|
4
|
+
data.tar.gz: 2f6a58a3d500f26aead0cd1a499929a6175389f4990a6b157dbbdf98441a1afa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46f011748ced9a35caf7a704a69c36b06ec5e8a1c06626e565980daed4bad8d5ec2506c6cb865dcc0fe86a73cad9484c6ae4a915fe32930faeb56f7214b3759b
|
7
|
+
data.tar.gz: 18fc8bdde9eeaa4eb618b5b244bb7de20da92886d13459bb0806e5318dcefe04a1105cf026bd2d516baaf43ab531bd78e5fc0b37f0744b4c21e4f16a2b4126a3
|
@@ -0,0 +1,43 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
paths:
|
6
|
+
- 'lib/pinject/version.rb'
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
name: Build + Publish
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
permissions:
|
12
|
+
contents: read
|
13
|
+
packages: write
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby 2.6
|
18
|
+
uses: actions/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 3.0.3
|
21
|
+
|
22
|
+
- name: Publish to GPR
|
23
|
+
run: |
|
24
|
+
mkdir -p $HOME/.gem
|
25
|
+
touch $HOME/.gem/credentials
|
26
|
+
chmod 0600 $HOME/.gem/credentials
|
27
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
28
|
+
gem build *.gemspec
|
29
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
30
|
+
env:
|
31
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
32
|
+
OWNER: ${{ github.repository_owner }}
|
33
|
+
|
34
|
+
- name: Publish to RubyGems
|
35
|
+
run: |
|
36
|
+
mkdir -p $HOME/.gem
|
37
|
+
touch $HOME/.gem/credentials
|
38
|
+
chmod 0600 $HOME/.gem/credentials
|
39
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
40
|
+
gem build *.gemspec
|
41
|
+
gem push *.gem
|
42
|
+
env:
|
43
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
- name: Set up Ruby
|
26
|
+
uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: ${{ matrix.ruby-version }}
|
29
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
30
|
+
- name: Run tests
|
31
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2021-12-22 01:50:28 UTC using RuboCop version 1.23.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
# Configuration parameters: EnforcedStyleAlignWith, Severity.
|
12
|
+
# SupportedStylesAlignWith: keyword, variable, start_of_line
|
13
|
+
Layout/EndAlignment:
|
14
|
+
Exclude:
|
15
|
+
- 'lib/pinject/docker.rb'
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Configuration parameters: AllowSafeAssignment.
|
19
|
+
Lint/AssignmentInCondition:
|
20
|
+
Exclude:
|
21
|
+
- 'lib/pinject/docker.rb'
|
22
|
+
|
23
|
+
# Offense count: 3
|
24
|
+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
25
|
+
Metrics/AbcSize:
|
26
|
+
Max: 21
|
27
|
+
|
28
|
+
# Offense count: 1
|
29
|
+
# Configuration parameters: CountComments, CountAsOne.
|
30
|
+
Metrics/ClassLength:
|
31
|
+
Max: 112
|
32
|
+
|
33
|
+
# Offense count: 4
|
34
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
35
|
+
Metrics/MethodLength:
|
36
|
+
Max: 21
|
37
|
+
|
38
|
+
# Offense count: 2
|
39
|
+
# Configuration parameters: ForbiddenDelimiters.
|
40
|
+
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
|
41
|
+
Naming/HeredocDelimiterNaming:
|
42
|
+
Exclude:
|
43
|
+
- 'lib/pinject/docker.rb'
|
44
|
+
|
45
|
+
# Offense count: 2
|
46
|
+
# Configuration parameters: AllowedConstants.
|
47
|
+
Style/Documentation:
|
48
|
+
Exclude:
|
49
|
+
- 'spec/**/*'
|
50
|
+
- 'test/**/*'
|
51
|
+
- 'lib/pinject.rb'
|
52
|
+
- 'lib/pinject/docker.rb'
|
53
|
+
|
54
|
+
# Offense count: 3
|
55
|
+
# Configuration parameters: MinBodyLength.
|
56
|
+
Style/GuardClause:
|
57
|
+
Exclude:
|
58
|
+
- 'lib/pinject/docker.rb'
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at pyama@pepabo.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pinject (0.1.4)
|
5
|
+
docker-api
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
docker-api (2.2.0)
|
12
|
+
excon (>= 0.47.0)
|
13
|
+
multi_json
|
14
|
+
excon (0.89.0)
|
15
|
+
multi_json (1.15.0)
|
16
|
+
parallel (1.21.0)
|
17
|
+
parser (3.0.3.2)
|
18
|
+
ast (~> 2.4.1)
|
19
|
+
rainbow (3.0.0)
|
20
|
+
rake (13.0.6)
|
21
|
+
regexp_parser (2.2.0)
|
22
|
+
rexml (3.2.5)
|
23
|
+
rubocop (1.23.0)
|
24
|
+
parallel (~> 1.10)
|
25
|
+
parser (>= 3.0.0.0)
|
26
|
+
rainbow (>= 2.2.2, < 4.0)
|
27
|
+
regexp_parser (>= 1.8, < 3.0)
|
28
|
+
rexml
|
29
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
30
|
+
ruby-progressbar (~> 1.7)
|
31
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
32
|
+
rubocop-ast (1.15.0)
|
33
|
+
parser (>= 3.0.1.1)
|
34
|
+
ruby-progressbar (1.11.0)
|
35
|
+
unicode-display_width (2.1.0)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
x86_64-darwin-20
|
39
|
+
x86_64-linux
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
pinject!
|
43
|
+
rake (~> 13.0)
|
44
|
+
rubocop (~> 1.21)
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
2.2.33
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 pyama
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Pinject
|
2
|
+
|
3
|
+
Inject package upgrade command to your docker images.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pinject'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pinject
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
you can inject os update command to some docker images.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
image = Pinject.new("ubuntu:latest")
|
27
|
+
inject_image = image.inject_build("pyama:ubuntu_inject") # run apt-get upgrade
|
28
|
+
inject_image.push
|
29
|
+
```
|
30
|
+
|
31
|
+
## Support Dist
|
32
|
+
- ubuntu
|
33
|
+
- centos
|
34
|
+
- alpine
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake ` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pinject. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/pinject/blob/master/CODE_OF_CONDUCT.md).
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
49
|
+
|
50
|
+
## Code of Conduct
|
51
|
+
|
52
|
+
Everyone interacting in the Pinject project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pinject/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/exe/pinject
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'docker'
|
4
|
+
require 'digest/md5'
|
5
|
+
require 'fileutils'
|
6
|
+
module Pinject
|
7
|
+
class Docker
|
8
|
+
attr_reader :log
|
9
|
+
|
10
|
+
::Docker.authenticate!(
|
11
|
+
'username' => ENV['DOCKER_USER'],
|
12
|
+
'password' => ENV['DOCKER_PASSWORD'],
|
13
|
+
'serveraddress' => ENV['DOCKER_REGISTRY']
|
14
|
+
) if %w(DOCKER_USER DOCKER_PASSWORD DOCKER_REGISTRY).all? {|a| ENV[a] }
|
15
|
+
|
16
|
+
def initialize(image_name, log: false)
|
17
|
+
@image_name = image_name
|
18
|
+
@log = log
|
19
|
+
end
|
20
|
+
|
21
|
+
def inject_build(repo)
|
22
|
+
if r = detect_os
|
23
|
+
Pinject.log.info "detect os #{r.inspect}" if log
|
24
|
+
upd = update_cmd(r[:dist], r[:version])
|
25
|
+
if upd
|
26
|
+
df = docker_file(@image_name, upd, r[:user])
|
27
|
+
::Docker::Image.build(
|
28
|
+
df,
|
29
|
+
't' => repo
|
30
|
+
) do |v|
|
31
|
+
Pinject.log.info v if log
|
32
|
+
end
|
33
|
+
else
|
34
|
+
raise UnsupportedDistError, "unsupport os dist:#{r[:dist]} version:#{r[:version]}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def detect_os
|
42
|
+
::Docker::Container.all(all: true).each do |c|
|
43
|
+
c.delete(force: true) if c.info['Names'].first == "/#{container_name}"
|
44
|
+
end
|
45
|
+
|
46
|
+
container = ::Docker::Container.create({
|
47
|
+
'name' => container_name,
|
48
|
+
'Image' => image.id,
|
49
|
+
'Entrypoint' => '',
|
50
|
+
'Cmd' => ['/opt/detector']
|
51
|
+
})
|
52
|
+
|
53
|
+
result = nil
|
54
|
+
t = Thread.new { container.attach { |stream, chunk| result = chunk.chomp if stream == :stdout } }
|
55
|
+
container.start
|
56
|
+
t.join
|
57
|
+
|
58
|
+
if result
|
59
|
+
dist, version, user = result.split(%r{:|/})
|
60
|
+
|
61
|
+
{
|
62
|
+
dist: dist,
|
63
|
+
version: version,
|
64
|
+
user: user
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def docker_file(image, cmd, user)
|
70
|
+
t = <<~EOS
|
71
|
+
FROM %s
|
72
|
+
USER root
|
73
|
+
RUN %s
|
74
|
+
USER %s
|
75
|
+
EOS
|
76
|
+
format(t, image, cmd, user)
|
77
|
+
end
|
78
|
+
|
79
|
+
def container_name
|
80
|
+
Digest::MD5.hexdigest(@image_name)[0..10]
|
81
|
+
end
|
82
|
+
|
83
|
+
def image
|
84
|
+
Pinject.log.info 'start detect os' if log
|
85
|
+
::Docker.options[:read_timeout] = 300
|
86
|
+
begin
|
87
|
+
i = ::Docker::Image.create('fromImage' => @image_name)
|
88
|
+
rescue StandardError => e
|
89
|
+
Pinject.log.error "failed create container #{e.inspect}" if log
|
90
|
+
raise e
|
91
|
+
end
|
92
|
+
|
93
|
+
t = Tempfile.open('detector') do |f|
|
94
|
+
f.puts detector_code
|
95
|
+
f
|
96
|
+
end
|
97
|
+
FileUtils.chmod(0o755, t.path)
|
98
|
+
i.insert_local('localPath' => t.path, 'outputPath' => '/opt/detector')
|
99
|
+
end
|
100
|
+
|
101
|
+
def update_cmd(dist, version)
|
102
|
+
r = case dist
|
103
|
+
when 'ubuntu', 'debian'
|
104
|
+
['apt-get update -qqy', 'apt-get upgrade -qqy', 'apt-get clean', 'rm -rf /var/lib/apt/lists/*']
|
105
|
+
when 'alpine'
|
106
|
+
['apk update', 'apk upgrade --no-cache']
|
107
|
+
when 'centos'
|
108
|
+
case version
|
109
|
+
when '5', '6'
|
110
|
+
nil
|
111
|
+
else
|
112
|
+
['yum update -y']
|
113
|
+
end
|
114
|
+
end
|
115
|
+
r&.join(' && ')
|
116
|
+
end
|
117
|
+
|
118
|
+
def detector_code
|
119
|
+
<<~EOS
|
120
|
+
#!/bin/sh
|
121
|
+
if [ -f /etc/lsb-release ]; then
|
122
|
+
. /etc/lsb-release
|
123
|
+
OS=$DISTRIB_ID
|
124
|
+
VER=`echo $DISTRIB_RELEASE | awk -F. '{ print $1 }'`
|
125
|
+
elif [ -f /etc/debian_version ]; then
|
126
|
+
OS=debian
|
127
|
+
VER=`cat /etc/debian_version | awk -F. '{ print $1 }'`
|
128
|
+
elif [ -f /etc/redhat-release ]; then
|
129
|
+
OS=centos
|
130
|
+
VER=`cat /etc/redhat-release | sed -e 's/.*\\s\\([0-9]\\)\\..*/\\1/'`
|
131
|
+
elif [ -f /etc/alpine-release ]; then
|
132
|
+
OS=alpine
|
133
|
+
VER=`cat /etc/alpine-release | awk -F. '{ print $1 }'`
|
134
|
+
elif [ -f /etc/os-release]; then
|
135
|
+
. /etc/os-release
|
136
|
+
OS=$ID
|
137
|
+
VER=`echo $VERSION_ID | sed -e 's/"//g'`
|
138
|
+
else
|
139
|
+
OS="other"
|
140
|
+
VER="unknown"
|
141
|
+
fi
|
142
|
+
echo $OS/$VER:`whoami` | tr '[:upper:]' '[:lower:]'
|
143
|
+
EOS
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
data/lib/pinject.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'pinject/version'
|
4
|
+
require_relative 'pinject/docker'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
module Pinject
|
8
|
+
def self.log
|
9
|
+
@log ||= Logger.new($stdout)
|
10
|
+
end
|
11
|
+
|
12
|
+
class Error < StandardError; end
|
13
|
+
class UnsupportedDistError < StandardError; end
|
14
|
+
# Your code goes here...
|
15
|
+
end
|
data/pinject.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/pinject/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'pinject'
|
7
|
+
spec.version = Pinject::VERSION
|
8
|
+
spec.authors = ['pyama']
|
9
|
+
spec.email = ['pyama@pepabo.com']
|
10
|
+
|
11
|
+
spec.summary = 'inject package update commands to your docker images'
|
12
|
+
spec.description = 'detect os your docker image and update os pakaces.'
|
13
|
+
spec.homepage = 'https://github.com/pyama86/pinject'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = '>= 2.6.0'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/pyama86/pinject'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/pyama86/pinject/CHANGELOG.md'
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
spec.add_dependency 'docker-api'
|
26
|
+
end
|
data/sig/pinject.rbs
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pinject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pyama
|
@@ -27,10 +27,31 @@ dependencies:
|
|
27
27
|
description: detect os your docker image and update os pakaces.
|
28
28
|
email:
|
29
29
|
- pyama@pepabo.com
|
30
|
-
executables:
|
30
|
+
executables:
|
31
|
+
- pinject
|
31
32
|
extensions: []
|
32
33
|
extra_rdoc_files: []
|
33
|
-
files:
|
34
|
+
files:
|
35
|
+
- ".github/workflows/gem-push.yml"
|
36
|
+
- ".github/workflows/ruby.yml"
|
37
|
+
- ".gitignore"
|
38
|
+
- ".rubocop.yml"
|
39
|
+
- ".rubocop_todo.yml"
|
40
|
+
- CHANGELOG.md
|
41
|
+
- CODE_OF_CONDUCT.md
|
42
|
+
- Gemfile
|
43
|
+
- Gemfile.lock
|
44
|
+
- LICENSE.txt
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- bin/console
|
48
|
+
- bin/setup
|
49
|
+
- exe/pinject
|
50
|
+
- lib/pinject.rb
|
51
|
+
- lib/pinject/docker.rb
|
52
|
+
- lib/pinject/version.rb
|
53
|
+
- pinject.gemspec
|
54
|
+
- sig/pinject.rbs
|
34
55
|
homepage: https://github.com/pyama86/pinject
|
35
56
|
licenses:
|
36
57
|
- MIT
|