-
Notifications
You must be signed in to change notification settings - Fork 733
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve image building (primarily for discourse_dev)
Move "discourse" user and "/var/www" directory creation into base image so that discourse_dev can build from base image directly instead of requiring the overhead of the full discourse image. Remove discourse_fast_switch dependency from discourse_dev, and remove the ruby 2.2/2.0 logic, as Discourse already appears to require 2.3.0 or greater. Remove discourse_dev's independent `postgres.template.yml` and `redis.template.yml` files, and instead derive them from the top-level templates directory. This ensures that the discourse_dev image is always up-to-date with the discourse main image. Add password-less "sudo" permissions for the "discourse" user in the discourse_dev image. This simplifies (fixes) the "bundle install" command (and others) as implemented by discourse/bin/docker utilities. Add image/Makefile so that images can be built even on machines without Ruby installed. Logic is replicated from `image/build.rb`, and should result in equivalent images. (Perhaps build.rb should be removed?) Add automation in Makefile to ensure that all Dockerfiles are updated to match the version number in the Makefile. (This includes the `/VERSION` file written into the base image.) Add image/README.md to describe the images and process. Update ImageMagick to 6.9.5-9 in the base Dockerfile because 6.9.5-8 is no longer available. (Perhaps this dependency should be vendored.) Fix base "boot" failure caused by missing log files on a new instance (in `base/runit-1.d-00-fix-var-logs`). Before chowning the log files, "touch" them to ensure they exist. This failure previously prevented the discourse_dev `ensure-database` script from running, which made development use of discourse_dev very difficult. Update to version 1.3.7. (Driven by IMAGE_VERSION in the Makefile. Mostly, this is to ensure that the next official build of the images will be *at least* 1.3.7, superseding any previous versions.)
- Loading branch information
1 parent
0a27bab
commit 3447089
Showing
16 changed files
with
167 additions
and
251 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
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
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,76 @@ | ||
IMAGE_VERSION := 1.3.7 | ||
|
||
SHELL := /bin/bash | ||
OS := $(shell uname | tr '[:upper:]' '[:lower:]') | ||
|
||
DOCKER_SQUASH_URL := https://github.com/jwilder/docker-squash/releases/download/v0.2.0/docker-squash-${OS}-amd64-v0.2.0.tar.gz | ||
|
||
|
||
# omitting discourse_fast_switch from 'all' as it seems obsolete. | ||
all: base discourse discourse_dev discourse_test discourse_bench | ||
.PHONY: all base discourse discourse_dev discourse_test discourse_bench discourse_fast_switch | ||
|
||
base: base-deps | ||
# discourse: discourse-deps | ||
discourse_dev: discourse_dev-deps | ||
# discourse_test: discourse_test-deps | ||
# discourse_bench: discourse_bench-deps | ||
# discourse_fast_switch: discourse_fast_switch-deps | ||
|
||
base: | ||
@IMAGE_DIR=$@ IS_BASE=YES ${MAKE} build-image | ||
|
||
discourse discourse_fast_switch discourse_dev discourse_test discourse_bench: | ||
@IMAGE_DIR=$@ ${MAKE} build-image | ||
|
||
|
||
base-deps: base/phantomjs | ||
.PHONY: base-deps | ||
|
||
base/phantomjs: | ||
@echo "Fetching phantomjs..." | ||
cd base && ./download_phantomjs | ||
|
||
discourse_dev-deps: | ||
@echo "Copying postgres and redis templates..." | ||
sed -e 's/\(db_name: discourse\)/\1_development/' ../templates/postgres.template.yml > discourse_dev/postgres.template.yml | ||
cp ../templates/redis.template.yml discourse_dev/redis.template.yml | ||
.PHONY: discourse_dev-deps | ||
|
||
# docker-squash doesn't seem to work on OSX... there's an error about calling | ||
# tar with an unsuported "--xattrs" option. If/when that gets fixed, the ifeq | ||
# can be removed. For now, OSX skips the docker-squash step, so don't push | ||
# images built on OSX! | ||
build-image: docker-squash update-dockerfile | ||
@echo "----- building image: discourse/${IMAGE_DIR}:${IMAGE_VERSION} -----" | ||
ifeq ($(OS), darwin) | ||
docker build -t discourse/${IMAGE_DIR}:${IMAGE_VERSION} ${IMAGE_DIR} | ||
else | ||
docker build ${IMAGE_DIR} | tee .build.out | ||
@echo "squashing $(shell tail -1 .build.out | awk '/^Successfully built / {print $$3}')..." | ||
docker save -o img.tar $(shell tail -1 .build.out | awk '/^Successfully built / {print $$3}') | ||
./docker-squash -verbose -i img.tar -o squash.tar $(if $(IS_BASE),-from root) -t discourse/${IMAGE_DIR}:${IMAGE_VERSION} | ||
docker load -i squash.tar | ||
rm -f squash.tar | ||
rm -f img.tar | ||
rm -f .build.out | ||
endif | ||
.PHONY: build-image | ||
|
||
docker-squash: | ||
wget ${DOCKER_SQUASH_URL} --output-document=$@.tar.gz | ||
tar -xzvf $@.tar.gz | ||
rm -f $@.tar.gz | ||
|
||
# We want to ensure that the Dockerfiles all have an appropriate header | ||
# comment, and any FROM line refers to the version we're currently building. | ||
# Also, if there's a line that echoes into VERSION, replace the value with the | ||
# current version. (Dockerfiles support environment expansion, but not for | ||
# FROM or RUN statements.) | ||
update-dockerfile: | ||
@echo "----- updating ${IMAGE_DIR}/Dockerfile for ${IMAGE_VERSION} -----" | ||
@sed -i '' -e 's/^\(# NAME:\).*$$/\1 discourse\/${IMAGE_DIR}/' ${IMAGE_DIR}/Dockerfile | ||
@sed -i '' -e 's/^\(# VERSION:\).*$$/\1 ${IMAGE_VERSION}/' ${IMAGE_DIR}/Dockerfile | ||
@sed -i '' -e 's/^\(FROM discourse\/[^:]*:\).*/\1${IMAGE_VERSION}/' ${IMAGE_DIR}/Dockerfile | ||
@sed -i '' -e 's/^\(RUN echo "\)[^"]*\(" > \/VERSION\)$$/\1${IMAGE_VERSION}\2/' ${IMAGE_DIR}/Dockerfile | ||
.PHONY: update-dockerfile |
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,45 @@ | ||
# Docker images | ||
|
||
## Building new images | ||
|
||
To build a new set of images, update the `Makefile` with the new version number, and then `make all`. This will automatically update the header comments in the Dockerfiles and update any `FROM` statements to ensure that the image verions remain in lock-step with each other. (The downside is that if you only wanted to tweak a "leaf" image, you'll still be touching/updating _all_ of the images. But reasoning about the images is much easier if they all have the same version.) | ||
|
||
> _A note about building on OSX:_ While the `Makefile` has provisions for acquiring an OS-specific version of docker-squash, running the Darwin (OSX) version doesn't work on my machine. To cope, OSX builds simply skip the docker-squash step. Since I'm not going to be pushing images up to Docker Hub, that's okay with me. | ||
The build process will tag the images with the version number, but not with "latest", nor will it push the images up to Docker Hub. Both of those steps must be performed manually. | ||
|
||
## More about the images | ||
|
||
See both `Makefile` and the respective `Dockerfile`s for details on _how_ all of this happens. | ||
|
||
|
||
### base ([discourse/base](https://hub.docker.com/r/discourse/base/)) | ||
|
||
All of the dependencies for running Discourse. This includes runit, postgres, nginx, ruby, imagemagick, etc. It also includes the creation of the "discourse" user and `/var/www` directory. | ||
|
||
|
||
### discourse ([discourse/discourse](https://hub.docker.com/r/discourse/discourse/)) | ||
|
||
Builds on the base image and adds the current (as of image build time) version of Discourse, cloned from GitHub, and also the bundled gems. | ||
|
||
|
||
### discourse_dev ([discourse/discourse_dev](https://hub.docker.com/r/discourse/discourse_dev/)) | ||
|
||
Adds redis and postgres just like the "standalone" template for Discourse in order to have an all-in-one container for development. Note that you are expected to mount your local discourse source directory to `/src`. See [the README in GitHub's discourse/bin/docker](https://github.com/discourse/discourse/tree/master/bin/docker/) for utilities that help with this. | ||
|
||
Note that the discourse user is granted "sudo" permission without asking for a password in the discourse_dev image. This is to facilitate the command-line Docker tools in discourse proper that run commands as the discourse user. | ||
|
||
|
||
### discourse_test ([discourse/discourse_test](https://hub.docker.com/r/discourse/discourse_test/)) | ||
|
||
Builds on the discourse image and adds testing tools and a default testing entrypoint. | ||
|
||
|
||
### discourse_bench ([discourse/discourse_bench](https://hub.docker.com/r/discourse/discourse_bench/)) | ||
|
||
Builds on the discourse_test image and adds benchmark testing. | ||
|
||
|
||
### discourse_fast_switch ([discourse/discourse_fast_switch](https://hub.docker.com/r/discourse/discourse_fast_switch/)) | ||
|
||
Builds on the discourse image and adds the ability to easily switch versions of Ruby. |
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
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
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,7 +1,6 @@ | ||
#!/bin/bash | ||
mkdir -p /var/log/nginx | ||
chown -R www-data:www-data /var/log/nginx | ||
chown www-data:www-data /var/log/nginx | ||
chown -f syslog:adm /var/log/syslog* | ||
chown -f syslog:adm /var/log/auth.log* | ||
chown -f syslog:adm /var/log/kern.log* | ||
touch /var/log/syslog && chown -f syslog:adm /var/log/syslog* | ||
touch /var/log/auth.log && chown -f syslog:adm /var/log/auth.log* | ||
touch /var/log/kern.log && chown -f syslog:adm /var/log/kern.log* |
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
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
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
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
Oops, something went wrong.