Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use build-arg to set rubygems version #2548

Merged
merged 1 commit into from Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -47,7 +47,7 @@ script:
- script/build_docker.sh

env:
- RUBYGEMS_VERSION=2.6.10
- RUBYGEMS_VERSION=3.0.3
- RUBYGEMS_VERSION=latest

matrix:
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -64,7 +64,7 @@ Follow the instructions below on how to install Bundler and setup the database.
#### Environment (OS X)

* Use Ruby 2.6.x (`.ruby-version` is present and can be used)
* Use Rubygems 2.6.10
* Use Rubygems 3.0.3
* Install bundler: `gem install bundler`
* Install Elastic Search:
* Pull ElasticSearch `5.6.16` : `docker pull docker.elastic.co/elasticsearch/elasticsearch:5.6.16`
Expand All @@ -84,7 +84,7 @@ Follow the instructions below on how to install Bundler and setup the database.

* Use Ruby 2.6.x `apt-get install ruby2.6`
* Or install via [alternate methods](https://www.ruby-lang.org/en/downloads/)
* Use Rubygems 2.6.10
* Use Rubygems 3.0.3
* Install bundler: `gem install bundler`
* Install Elastic Search:
* Pull ElasticSearch `5.6.16` : `docker pull docker.elastic.co/elasticsearch/elasticsearch:5.6.16`
Expand Down
11 changes: 8 additions & 3 deletions Dockerfile
@@ -1,5 +1,7 @@
FROM ruby:2.6-alpine as build

ARG RUBYGEMS_VERSION

RUN apk add --no-cache \
nodejs \
postgresql-dev \
Expand All @@ -14,7 +16,7 @@ RUN apk add --no-cache \
RUN mkdir -p /app /app/config /app/log/
WORKDIR /app

RUN gem update --system 2.6.10
RUN gem update --system $RUBYGEMS_VERSION

COPY . /app

Expand All @@ -23,7 +25,7 @@ ADD https://s3-us-west-2.amazonaws.com/oregon.production.s3.rubygems.org/version
RUN mv /app/config/database.yml.example /app/config/database.yml


RUN gem install bundler io-console --no-ri --no-rdoc && \
RUN gem install bundler io-console --no-document && \
bundle config set --local without 'development test' && \
bundle install --jobs 20 --retry 5

Expand All @@ -35,6 +37,8 @@ RUN bundle config set --local without 'development test assets' && \

FROM ruby:2.6-alpine

ARG RUBYGEMS_VERSION

RUN apk add --no-cache \
libpq \
ca-certificates \
Expand All @@ -43,10 +47,11 @@ RUN apk add --no-cache \
xz-libs \
&& rm -rf /var/cache/apk/*

RUN gem update --system $RUBYGEMS_VERSION

RUN mkdir -p /app
WORKDIR /app

COPY --from=build /usr/local/bin/gem /usr/local/bin/gem
COPY --from=build /usr/local/bundle/ /usr/local/bundle/
COPY --from=build /app/ /app/

Expand Down
10 changes: 9 additions & 1 deletion script/build_docker.sh
Expand Up @@ -14,7 +14,7 @@ fi

echo "$TRAVIS_COMMIT" > REVISION

docker build -t quay.io/$TRAVIS_REPO_SLUG:$TRAVIS_COMMIT .
docker build -t quay.io/$TRAVIS_REPO_SLUG:$TRAVIS_COMMIT --build-arg RUBYGEMS_VERSION=$RUBYGEMS_VERSION .

docker run -e RAILS_ENV=production -e SECRET_KEY_BASE=1234 -e DATABASE_URL=postgresql://localhost \
--net host quay.io/$TRAVIS_REPO_SLUG:$TRAVIS_COMMIT \
Expand All @@ -32,6 +32,14 @@ if [ $? -eq 1 ]; then
exit 1
fi

rubygems_version_installed=$(docker run quay.io/$TRAVIS_REPO_SLUG:$TRAVIS_COMMIT -- gem -v)

if [ $rubygems_version_installed != $RUBYGEMS_VERSION ]; then
echo "Installed gem version doesn't match"
echo "expected: $RUBYGEMS_VERSION, found: $rubygems_version_installed"
exit 1
fi

if [ -z "$DOCKER_USERNAME" ] || [ -z "$DOCKER_PASSWORD" ]
then
exit 0
Expand Down