Skip to content

Commit

Permalink
Build a better docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
robotdana committed Jan 26, 2025
1 parent ed20f40 commit f0e4d6d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
9 changes: 6 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
/.simplecov
/.spellr.yml
/.travis.yml
/Gemfile.lock
/Dockerfile
/Rakefile
/vendor/
/.bundle/
/.github
/spec
/bin
/.spellr_wordlists
/pkg
/tmp
/coverage
/.ruby-version
/.rspec_status
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ jobs:
bundler-cache: true
- run: bundle exec rake build

docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: bin/docker_build

2 changes: 2 additions & 0 deletions .spellr_wordlists/shell.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
apk
euo
grep
musl
xeuo
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
FROM ruby:alpine
WORKDIR /spellr
COPY . .
COPY Gemfile spellr.gemspec .
COPY ./lib/spellr/version.rb ./lib/spellr/
RUN apk add --no-cache make musl-dev gcc && \
gem install bundler && \
bundle install --without=development
BUNDLE_WITHOUT=development bundle install

FROM ruby:alpine
COPY . /spellr
COPY --from=0 /usr/local/bundle /usr/local/bundle
WORKDIR /app
ENTRYPOINT ["/spellr/exe/spellr"]
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ task default: [:spec, :rubocop, :spellr, :leftovers, :build]

namespace :release do
task :dockerhub_push do
system("#{__dir__}/bin/dockerhub_push")
system('bin/dockerhub_push', chdir: __dir__)
end
end
Rake::Task[:release].enhance([:"release:dockerhub_push"])
Expand Down
14 changes: 14 additions & 0 deletions bin/docker_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -euo pipefail

version_tag=${1-"v$(grep -F VERSION lib/spellr/version.rb | cut -d"'" -f2)"}
if (( ${#version_tag} < 7 )); then
echo "version '$version_tag' doesn't look correct"
exit 1
fi

docker build -t robotdana/spellr:$version_tag -t robotdana/spellr:latest .

# prove it works
[[ v$(docker run -it -v $PWD:/app robotdana/spellr:$version_tag --version | tr -d '\r') == $version_tag ]]
7 changes: 2 additions & 5 deletions bin/dockerhub_push
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#!/usr/bin/env bash

set -euo pipefail
set -xeuo pipefail

version_tag=$(git describe --exact-match --abbrev=0)

docker build -t robotdana/spellr:$version_tag -t robotdana/spellr:latest .
# prove it works
docker run -it -v $PWD:/app robotdana/spellr:$version_tag --version
. ./bin/docker_build $version_tag

docker push robotdana/spellr:$version_tag
docker push robotdana/spellr:latest

0 comments on commit f0e4d6d

Please sign in to comment.