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

Branch based build #61

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions Dockerfile-build-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# docker build --file Dockerfile-build-branch \
# --build-arg SSH_KEY="$(cat ~/.ssh/id_rsa)" \
# --build-arg REPO="[email protected]:liquidvotingio/decidim.git" \
# --build-arg BRANCH="stateless-app-generator" \
# -t decidim-staging .

# Git repo checkout builder
# based on https://github.com/jnovack/git-checkout
FROM alpine:latest as repo-builder

WORKDIR /repo

ARG SSH_KEY
ENV SSH_KEY=$SSH_KEY
ARG REPO="[email protected]:decidim/decidim.git"
ENV REPO=$REPO
ARG BRANCH="develop"
ENV BRANCH=$BRANCH
ENV HASH="HEAD"

RUN apk add --no-cache git openssh

ENV USER=appuser
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/home/${USER}" \
--shell "/sbin/nologin" \
--uid "${UID}" \
"${USER}"
RUN chown -R appuser:appuser /repo
USER appuser:appuser

RUN /bin/mkdir -p ~/.ssh \
&& /bin/echo "[DEBUG] Copying ssh private key from environment ..." \
&& /bin/echo -e "$SSH_KEY" > ~/.ssh/id_rsa \
&& /bin/echo "[DEBUG] Using ~/.ssh/id_rsa ..." \
&& /bin/chmod 400 ~/.ssh/id_rsa \
&& eval $(ssh-agent -s) > /dev/null \
&& /usr/bin/ssh-add ~/.ssh/id_rsa

RUN /bin/echo -e "Host * \n StrictHostKeyChecking no" > ~/.ssh/config

RUN /bin/echo "[INFO ] Downloading from ${REPO} ..." \
&& /bin/echo "[INFO ] ... checking out ${BRANCH}" \
&& /bin/echo "[INFO ] ... resetting to ${HASH}"

RUN /bin/echo "[INFO ] Creating new repository ..." \
&& /bin/rm -rf * &> /dev/null || /bin/true \
&& /bin/rm -rf .* &> /dev/null || /bin/true \
&& /usr/bin/git clone -b "$BRANCH" \
--single-branch "$REPO" .

# && /usr/bin/git remote add origin "$REPO" \
# && /usr/bin/git fetch origin \
# && /usr/bin/git checkout --force "$BRANCH" \
# && /usr/bin/git reset --hard "$HASH" \

## Gem builder
# ARG ruby_version=2.7.1
FROM ruby:2.7.1

COPY --from=repo-builder /repo /repo

WORKDIR /repo

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

RUN apt-get install -y git imagemagick wget \
&& apt-get clean

RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& apt-get install -y nodejs \
&& apt-get clean

RUN npm install -g [email protected]

RUN gem install bundler --version '>= 2.1.4'

RUN bundle install

# Not yet available on decidim/decidim - will be submitted soon
RUN bundle exec rake decidim:generate_stateless_demo_app

# Before this can be run, there'll need to be a docker exec to run migrations
# and seeding through rake. This of course can only be done once container is up
# and running and with access to a database.
CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]

# So far trying to avoid using an entrypoint script
ENTRYPOINT []