From 319bcf51a809d6e04ecc18bc0c4798041592810a Mon Sep 17 00:00:00 2001 From: Oliver Azevedo Barnes Date: Tue, 8 Dec 2020 18:22:59 +0000 Subject: [PATCH 1/5] WIP building from specific branch --- Dockerfile-build-branch | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Dockerfile-build-branch diff --git a/Dockerfile-build-branch b/Dockerfile-build-branch new file mode 100644 index 0000000..9eb6ec4 --- /dev/null +++ b/Dockerfile-build-branch @@ -0,0 +1,76 @@ +# 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 +ENV REPO="git@github.com:decidim/decidim.git" +ENV BRANCH="develop" +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 + +# ENV LANG C.UTF-8 +# ENV LC_ALL C.UTF-8 + +# WORKDIR /code + +# 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 npm@6.3.0 + +# RUN gem install bundler --version '>= 2.1.4' + +# RUN + +# ENTRYPOINT [] From dd59d619e00fa1099ab384d80251b1f36d0e4f19 Mon Sep 17 00:00:00 2001 From: Oliver Azevedo Barnes Date: Wed, 9 Dec 2020 11:55:11 +0000 Subject: [PATCH 2/5] More WIP --- Dockerfile-build-branch | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Dockerfile-build-branch b/Dockerfile-build-branch index 9eb6ec4..739b70f 100644 --- a/Dockerfile-build-branch +++ b/Dockerfile-build-branch @@ -1,3 +1,5 @@ +# docker build --file Dockerfile-build-branch --build-arg SSH_KEY="$(cat ~/.ssh/id_rsa)" -t decidim-staging . + # Git repo checkout builder # based on https://github.com/jnovack/git-checkout FROM alpine:latest as repo-builder @@ -53,24 +55,24 @@ RUN /bin/echo "[INFO ] Creating new repository ..." \ # ARG ruby_version=2.7.1 FROM ruby:2.7.1 -# COPY --from=repo-builder . /repo +COPY --from=repo-builder /repo /repo -# ENV LANG C.UTF-8 -# ENV LC_ALL C.UTF-8 +WORKDIR /repo -# WORKDIR /code +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 -# RUN apt-get install -y git imagemagick wget \ -# && apt-get clean +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 curl -sL https://deb.nodesource.com/setup_10.x | bash - \ + && apt-get install -y nodejs \ + && apt-get clean -# RUN npm install -g npm@6.3.0 +RUN npm install -g npm@6.3.0 -# RUN gem install bundler --version '>= 2.1.4' +RUN gem install bundler --version '>= 2.1.4' # RUN -# ENTRYPOINT [] +ENTRYPOINT [] From e91db5f67f73e3f9633252722c47ba8764c79ef8 Mon Sep 17 00:00:00 2001 From: Oliver Azevedo Barnes Date: Wed, 9 Dec 2020 19:53:03 +0000 Subject: [PATCH 3/5] Build args for repo and branch --- Dockerfile-build-branch | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Dockerfile-build-branch b/Dockerfile-build-branch index 739b70f..84eafdc 100644 --- a/Dockerfile-build-branch +++ b/Dockerfile-build-branch @@ -1,4 +1,8 @@ -# docker build --file Dockerfile-build-branch --build-arg SSH_KEY="$(cat ~/.ssh/id_rsa)" -t decidim-staging . +# docker build --file Dockerfile-build-branch \ +# --build-arg SSH_KEY="$(cat ~/.ssh/id_rsa)" \ +# --build-arg REPO="git@github.com:liquidvotingio/decidim.git" \ +# --build-arg BRANCH="feature/allow-admin-discarded-to-tech-eval" \ +# -t decidim-staging . # Git repo checkout builder # based on https://github.com/jnovack/git-checkout @@ -8,8 +12,10 @@ WORKDIR /repo ARG SSH_KEY ENV SSH_KEY=$SSH_KEY -ENV REPO="git@github.com:decidim/decidim.git" -ENV BRANCH="develop" +ARG REPO="git@github.com:decidim/decidim.git" +ENV REPO=$REPO +ARG BRANCH="develop" +ENV BRANCH=$BRANCH ENV HASH="HEAD" RUN apk add --no-cache git openssh @@ -73,6 +79,8 @@ RUN npm install -g npm@6.3.0 RUN gem install bundler --version '>= 2.1.4' -# RUN +RUN bundle install + +# RUN bundle exec rake development_app ENTRYPOINT [] From 6b94c66aafc31391d4d2cab3d368c934c9525133 Mon Sep 17 00:00:00 2001 From: Oliver Azevedo Barnes Date: Thu, 10 Dec 2020 19:14:00 +0000 Subject: [PATCH 4/5] Add stateless demo app generation step --- Dockerfile-build-branch | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile-build-branch b/Dockerfile-build-branch index 84eafdc..f9cec28 100644 --- a/Dockerfile-build-branch +++ b/Dockerfile-build-branch @@ -1,7 +1,7 @@ # docker build --file Dockerfile-build-branch \ # --build-arg SSH_KEY="$(cat ~/.ssh/id_rsa)" \ # --build-arg REPO="git@github.com:liquidvotingio/decidim.git" \ -# --build-arg BRANCH="feature/allow-admin-discarded-to-tech-eval" \ +# --build-arg BRANCH="stateless-app-generator" \ # -t decidim-staging . # Git repo checkout builder @@ -81,6 +81,7 @@ RUN gem install bundler --version '>= 2.1.4' RUN bundle install -# RUN bundle exec rake development_app +# Not yet available on decidim/decidim - will be submitted soon +RUN bundle exec rake decidim:generate_stateless_demo_app ENTRYPOINT [] From c7fca9343baead18be416df43eee8343c790ae06 Mon Sep 17 00:00:00 2001 From: Oliver Azevedo Barnes Date: Thu, 10 Dec 2020 19:14:36 +0000 Subject: [PATCH 5/5] Add rails server CMD --- Dockerfile-build-branch | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Dockerfile-build-branch b/Dockerfile-build-branch index f9cec28..d1ec2be 100644 --- a/Dockerfile-build-branch +++ b/Dockerfile-build-branch @@ -84,4 +84,10 @@ 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 []