-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from oliverbarnes/publish-image-on-github
Build and publish 'decidim' and 'decidim-generator' images on Github.
- Loading branch information
Showing
9 changed files
with
182 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
LABEL maintainer="[email protected]" | ||
|
||
ARG decidim_version | ||
|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters