我正在尝试为托管在Gitlab上的dockerized Rails项目设置CI / CD。经过一番阅读之后,我终于遵循了docker-compose仅对开发有用的想法,因为生产构建将通过直接的docker build命令进行。
因此,我在Gitlab CI上触发了我的管道,但遇到了与RAILS_MASTER_KEY
相关的故障。过了一会儿,我发现更好的选择是在我的.gitlab-ci.yml
中调用它之前,先在存储库(设置> CI)中定义此变量,如下所示。
我的问题是,无论如何尝试,我都会由于“无效的base64”或缺少密钥而收到错误消息。关于这个问题有很多读物,但是没有什么让我解决它。
image: docker
services:
- docker:dind
cache:
paths:
- node_modules
stages:
- build
- test
- release
- deploy # staging ?
build:
stage: build
before_script:
- apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
- pip install docker-compose
- docker-compose --version
script:
- docker-compose build
- docker-compose run app docker/wait_for_it.sh db:5433 -- "rake db:create db:migrate"
test:
stage: test
before_script:
- apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
- pip install docker-compose
- docker-compose --version
script:
- docker-compose --version
# Here we will run tests when available...
release:
stage: release
only:
- "feat-dockerisation"
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- echo "$RAILS_MASTER_KEY" | tr -d '\r' > config/master.key
script:
- docker build -t registry.gitlab.com/soykje/beweeg-ror:latest --pull .
- docker push registry.gitlab.com/soykje/beweeg-ror:latest
after_script:
- docker logout registry.gitlab.com
Dockerfile
FROM ruby:2.5.5-slim
ARG PRECOMPILEASSETS
RUN apt-get update && apt-get install -y curl gnupg
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN curl -q https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get -y update && \
apt-get install --fix-missing --no-install-recommends -qq -y \
build-essential \
vim \
wget gnupg \
git-all \
curl \
ssh \
postgresql-client-10 libpq5 libpq-dev -y && \
wget -qO- https://deb.nodesource.com/setup_9.x | bash - && \
apt-get install -y nodejs && \
wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install yarn && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN gem install bundler
#Install gems
RUN mkdir /gems
WORKDIR /gems
COPY Gemfile .
COPY Gemfile.lock .
RUN bundle install
ARG INSTALL_PATH=/opt/beweeg
ENV INSTALL_PATH $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY . .
# Precompile assets (or not)
RUN docker/potential_asset_precompile.sh $PRECOMPILEASSETS