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

Build and publish 'decidim' and 'decidim-generator' images on Github. #50

Merged
merged 2 commits into from
Dec 9, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: CI

on:
workflow_dispatch:
push:
branches:
- master
paths:
- 'Dockerfile'
- '.github/workflows/on_push.yml'

jobs:
build-publish:
name: Build & Publish Docker Image
runs-on: ubuntu-latest
env:
GENERATOR_IMAGE_NAME: ghcr.io/${{ github.actor }}/decidim-generator
APP_IMAGE_NAME: ghcr.io/${{ github.actor }}/decidim
TAG: ${{ github.sha }}

steps:
- name: Fetch Decidim Tag
id: decidim-tag
uses: oprypin/find-latest-tag@v1
with:
repository: decidim/decidim
releases-only: true

- name: Set Ruby Version
id: ruby-version
env:
RUBY_VERSION_URL: https://raw.githubusercontent.com/decidim/decidim/${{ steps.decidim-tag.outputs.tag }}/.ruby-version
run: |
echo ::set-output name=version::$(curl -s $RUBY_VERSION_URL)

- name: Set Decidim Version
id: decidim-version
run: echo ::set-output name=version::$(echo ${{ steps.decidim-tag.outputs.tag }} | cut -c2-)

- name: Checkout Our Repo
uses: actions/checkout@v2

- name: Build decidim-generator Image
env:
RUBY_VERSION: ${{ steps.ruby-version.outputs.version }}
DECIDIM_VERSION: ${{ steps.decidim-version.outputs.version }}
run: |
docker build \
--build-arg ruby_version=$RUBY_VERSION \
--build-arg decidim_version=$DECIDIM_VERSION \
-t $GENERATOR_IMAGE_NAME:$TAG .
docker tag $GENERATOR_IMAGE_NAME:$TAG $GENERATOR_IMAGE_NAME:latest
docker tag $GENERATOR_IMAGE_NAME:$TAG $GENERATOR_IMAGE_NAME:$DECIDIM_VERSION

- name: Publish Image to Github Container Registry
uses: azure/docker-login@v1
with:
login-server: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PAT_TOKEN }}
- run: |
docker push $GENERATOR_IMAGE_NAME

- name: Build decidim (app) Image
env:
RUBY_VERSION: ${{ steps.ruby-version.outputs.version }}
DECIDIM_VERSION: ${{ steps.decidim-version.outputs.version }}
run: |
docker build \
--file Dockerfile-deploy \
--build-arg base_image=$GENERATOR_IMAGE_NAME \
-t $APP_IMAGE_NAME:$TAG .
docker tag $APP_IMAGE_NAME:$TAG $APP_IMAGE_NAME:latest
docker tag $APP_IMAGE_NAME:$TAG $APP_IMAGE_NAME:$DECIDIM_VERSION

- name: Publish Image to Github Container Registry
uses: azure/docker-login@v1
with:
login-server: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PAT_TOKEN }}
- run: |
docker push $APP_IMAGE_NAME
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM ruby:2.7.1
ARG ruby_version

FROM ruby:${ruby_version}
tramuntanal marked this conversation as resolved.
Show resolved Hide resolved
LABEL maintainer="[email protected]"

ARG decidim_version
Expand All @@ -18,6 +20,6 @@ RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
RUN npm install -g [email protected]

RUN gem install bundler --version '>= 2.1.4' \
&& gem install decidim:$decidim_version
&& gem install decidim:${decidim_version}

ENTRYPOINT ["decidim"]
18 changes: 9 additions & 9 deletions Dockerfile-deploy
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
ARG base_image=decidim/decidim:latest
ARG base_image=ghcr.io/decidim/decidim-generator:latest

FROM $base_image
LABEL maintainer="[email protected]"

RUN decidim .
RUN bundle check || bundle install
RUN bundle exec rake assets:precompile

ENV RAILS_ENV=production
ENV PORT=3000
ENV RAILS_SERVE_STATIC_FILES=true

ONBUILD COPY Gemfile Gemfile.lock ./
ONBUILD RUN bundle install
ONBUILD COPY . .
ONBUILD RUN bundle install
ONBUILD RUN bundle exec rake assets:precompile
EXPOSE 3000

ENTRYPOINT []
ENV RAILS_SERVE_STATIC_FILES=true
CMD bundle exec rails s

CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]
53 changes: 42 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,56 @@
# Docker files for Decidim [![CircleCI](https://circleci.com/gh/decidim/docker.svg?style=svg)](https://circleci.com/gh/decidim/docker)
# Docker images for Decidim

## Docker images for development.
There are two official images available for Decidim on Github Packages: `decidim` and `decidim-generator`.

The development image is intended to be in conjunction with docker-compose. This image includes an script that makes feasible to keep ownership of the files created inside the container for for the user used ouside it.
The `decidim` image is a dockerized Decidim app with standard core modules. It can be used for quickly spinning up a local instance and kick the tires, or for deployment if all you need are the core modules.

It is convenient, but not absolutely mandatory that you create a volume for the /usr/local/bundle folder.
The `decidim-generator` image is a base environment with all you need to generate a new Decidim app locally. It is also the base image from which the `decidim` image is built.

## How to use it
## Using the decidim (app) image

With this docker image you can generate a new Decidim application. For instance for an application called HelloWorld:
With this image you can run a pre-generated Decidim app:

```bash
docker run -it --rm \
-e DATABASE_USERNAME=postgres \
-e DATABASE_PASSWORD=postgres \
-e DATABASE_HOST=host.docker.internal \
-e RAILS_ENV=development \
-p 3000:3000 \
ghcr.io/decidim/decidim:latest
```

```bash
docker run -it --rm \
-e DATABASE_URL="postgres://user:pass@postgres-host/decidim-production-db" \
-p 3000:3000 \
ghcr.io/decidim/decidim:latest
```

## Using the decidim-generator image

With this image you can generate a new Decidim application:

```bash
APP_NAME=HelloWorld
docker run -it -v "$(pwd):/code" decidim/decidim ${APP_NAME}
IMAGE=ghcr.io/decidim/decidim-generator:latest
docker run -it -v "$(pwd):/code" ${IMAGE} ${APP_NAME}
sudo chown -R $(whoami): ${APP_NAME}
```

Then you can continue with the process detailed on [Getting Started](https://github.com/decidim/decidim/blob/master/docs/getting_started.md).
From here on you can follow the steps on the [Getting Started](https://github.com/decidim/decidim/blob/master/docs/getting_started.md) guide.

### Using decidim-generator with docker-compose

The generator image can be used in conjunction with docker-compose, and the core [decidim/decidim](https://github.com/decidim/decidim) repo already offers a [docker-compose.yml](https://github.com/decidim/decidim/blob/develop/docker-compose.yml) file (currently pointing to the Docker Hub `decidim/decidim:latest-dev` image).

It is convenient, but not absolutely mandatory to create a volume for the /usr/local/bundle folder.

## Docker Hub images

We're in the process of adopting Github Actions for our automated image build and publishing, and while that flow currently only publishes to Github Packages, there's another flow on circleci publishing images to Docker Hub.

## Publish a new version
We plan to phase out the circleci flow soon, and publish to Docker Hub with Github Actions as well.

To publish a new version on [Docker Hub](https://hub.docker.com/r/decidim/decidim/) it's necessary to make a PR and change the DECIDIM_VERSION on circle-ci.yml to the last pulished version on rubygems.
Meanwhile, be aware that Docker Hub and Github Package images are gradually diverging.

CircleCI will execute automatically the bash scripts on scripts/ to build the images and publish them on Docker Hub.
23 changes: 23 additions & 0 deletions dockerhub/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ruby:2.7.1
LABEL maintainer="[email protected]"

ARG decidim_version

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 [email protected]

RUN gem install bundler --version '>= 2.1.4' \
&& gem install decidim:$decidim_version

ENTRYPOINT ["decidim"]
17 changes: 17 additions & 0 deletions dockerhub/Dockerfile-deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG base_image=decidim/decidim:latest

FROM $base_image
LABEL maintainer="[email protected]"

ENV RAILS_ENV=production
ENV PORT=3000

ONBUILD COPY Gemfile Gemfile.lock ./
ONBUILD RUN bundle install
ONBUILD COPY . .
ONBUILD RUN bundle install
ONBUILD RUN bundle exec rake assets:precompile

ENTRYPOINT []
ENV RAILS_SERVE_STATIC_FILES=true
CMD bundle exec rails s
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions scripts/build_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ latest_version=$(curl https://rubygems.org/api/v1/versions/decidim/latest.json |
version=${DECIDIM_VERSION:-$latest_version}
extra_args=("$@")

docker build --file Dockerfile \
docker build --file dockerhub/Dockerfile \
--build-arg "decidim_version=$version" \
--tag "decidim/decidim:$sha1" \
--tag "decidim/decidim:$version" \
--tag "decidim/decidim:latest" \
"${extra_args[@]}" .

docker build --file Dockerfile-test \
docker build --file dockerhub/Dockerfile-test \
--build-arg "base_image=decidim/decidim:$sha1" \
--build-arg "decidim_version=$version" \
--tag "decidim/decidim:$sha1-test" \
--tag "decidim/decidim:$version-test" \
--tag "decidim/decidim:latest-test" \
"${extra_args[@]}" .

docker build --file Dockerfile-dev \
docker build --file dockerhub/Dockerfile-dev \
--build-arg "base_image=decidim/decidim:$sha1-test" \
--tag "decidim/decidim:$sha1-dev" \
--tag "decidim/decidim:$version-dev" \
--tag "decidim/decidim:latest-dev" \
"${extra_args[@]}" .

docker build --file Dockerfile-deploy \
docker build --file dockerhub/Dockerfile-deploy \
--build-arg "base_image=decidim/decidim:$sha1" \
--tag "decidim/decidim:$sha1-deploy" \
--tag "decidim/decidim:$version-deploy" \
Expand Down