diff --git a/.github/workflows/on_push.yml b/.github/workflows/on_push.yml new file mode 100644 index 0000000..eec89a8 --- /dev/null +++ b/.github/workflows/on_push.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index 89e87d6..7fcd21e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM ruby:2.7.1 +ARG ruby_version + +FROM ruby:${ruby_version} LABEL maintainer="info@coditramuntana.com" ARG decidim_version @@ -18,6 +20,6 @@ RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \ RUN npm install -g npm@6.3.0 RUN gem install bundler --version '>= 2.1.4' \ - && gem install decidim:$decidim_version + && gem install decidim:${decidim_version} ENTRYPOINT ["decidim"] diff --git a/Dockerfile-deploy b/Dockerfile-deploy index 02f2354..d7eb906 100644 --- a/Dockerfile-deploy +++ b/Dockerfile-deploy @@ -1,17 +1,17 @@ -ARG base_image=decidim/decidim:latest +ARG base_image=ghcr.io/decidim/decidim-generator:latest FROM $base_image LABEL maintainer="info@coditramuntana.com" +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"] diff --git a/README.md b/README.md index a504a71..ca57060 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/dockerhub/Dockerfile b/dockerhub/Dockerfile new file mode 100644 index 0000000..89e87d6 --- /dev/null +++ b/dockerhub/Dockerfile @@ -0,0 +1,23 @@ +FROM ruby:2.7.1 +LABEL maintainer="info@coditramuntana.com" + +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 npm@6.3.0 + +RUN gem install bundler --version '>= 2.1.4' \ + && gem install decidim:$decidim_version + +ENTRYPOINT ["decidim"] diff --git a/dockerhub/Dockerfile-deploy b/dockerhub/Dockerfile-deploy new file mode 100644 index 0000000..02f2354 --- /dev/null +++ b/dockerhub/Dockerfile-deploy @@ -0,0 +1,17 @@ +ARG base_image=decidim/decidim:latest + +FROM $base_image +LABEL maintainer="info@coditramuntana.com" + +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 diff --git a/Dockerfile-dev b/dockerhub/Dockerfile-dev similarity index 100% rename from Dockerfile-dev rename to dockerhub/Dockerfile-dev diff --git a/Dockerfile-test b/dockerhub/Dockerfile-test similarity index 100% rename from Dockerfile-test rename to dockerhub/Dockerfile-test diff --git a/scripts/build_images.sh b/scripts/build_images.sh index f1c0555..5c1de2a 100755 --- a/scripts/build_images.sh +++ b/scripts/build_images.sh @@ -7,14 +7,14 @@ 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" \ @@ -22,14 +22,14 @@ docker build --file Dockerfile-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" \