From 546e388b9bbaa66347d411dd25c0d1d30207cd11 Mon Sep 17 00:00:00 2001 From: tyranron Date: Wed, 9 Oct 2019 11:41:47 +0200 Subject: [PATCH] Prepare release to Docker Hub --- .gitignore | 2 +- .travis.yml | 4 +-- Dockerfile | 68 ++++++++++++++++++++++++------------- LICENSE.md | 36 +++++++++++--------- Makefile | 84 +++++++++++++++++++++++++++++++--------------- README.md | 54 +++++++++++++++++++---------- hooks/post_push | 2 +- post_push.tmpl.php | 2 +- test/suite.bats | 36 +++++++++++++++----- 9 files changed, 191 insertions(+), 97 deletions(-) diff --git a/.gitignore b/.gitignore index 007c538..5e2d86c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /.idea/ -*.iml +/*.iml .DS_Store /node_modules/ diff --git a/.travis.yml b/.travis.yml index ebe7df5..63747b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,11 @@ services: - docker before_script: - - make image VERSION=test + - make image tag=test - make deps.bats script: - - make test VERSION=test + - make test tag=test notifications: email: diff --git a/Dockerfile b/Dockerfile index e926679..60c75b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,51 @@ -FROM debian:stretch-slim +# https://hub.docker.com/_/debian +FROM debian:buster-slim ARG firefox_ver=69.0 -ARG geckodriver_ver=v0.25.0 +ARG geckodriver_ver=0.25.0 RUN apt-get update \ - && apt-get install -y \ - wget tar bzip2 \ - # Install dependencies for firefox binary - `apt-cache depends firefox-esr | awk '/Depends:/{print$2}'` \ - # Install firefox - && wget -O FirefoxSetup.tar.bz2 "https://ftp.mozilla.org/pub/firefox/releases/${firefox_ver}/linux-x86_64/en-GB/firefox-${firefox_ver}.tar.bz2" \ - && tar xjf FirefoxSetup.tar.bz2 \ - && mv firefox /opt/firefox \ - # Install geckodriver - && wget https://github.com/mozilla/geckodriver/releases/download/v${geckodriver_ver}/geckodriver-v${geckodriver_ver}-linux64.tar.gz \ - && tar -xvzf geckodriver* \ - && chmod +x geckodriver \ - && mv geckodriver /usr/bin \ - # Provide MPLv2.0 license - && mkdir -p /usr/share/doc/mpl \ - && wget -O /usr/share/doc/mpl/MPLv2.0.html https://www.mozilla.org/en-US/MPL/2.0/ \ - # Cleanup unnecessary stuff - && apt-get purge -y --auto-remove \ - -o APT::AutoRemove::RecommendsImportant=false \ - && rm -rf /var/lib/apt/lists/* - -ENTRYPOINT ["geckodriver", "-b", "/opt/firefox/firefox", "--log", "debug", "--host", "0.0.0.0"] + && apt-get upgrade -y \ + && apt-get install -y --no-install-recommends --no-install-suggests \ + ca-certificates \ + && update-ca-certificates \ + \ + # Install tools for building + && toolDeps=" \ + curl bzip2 \ + " \ + && apt-get install -y --no-install-recommends --no-install-suggests \ + $toolDeps \ + \ + # Install dependencies for Firefox + && apt-get install -y --no-install-recommends --no-install-suggests \ + `apt-cache depends firefox-esr | awk '/Depends:/{print$2}'` \ + \ + # Download and install Firefox + && curl -fL -o /tmp/firefox.tar.bz2 \ + https://ftp.mozilla.org/pub/firefox/releases/${firefox_ver}/linux-x86_64/en-GB/firefox-${firefox_ver}.tar.bz2 \ + && tar -xjf /tmp/firefox.tar.bz2 -C /tmp/ \ + && mv /tmp/firefox /opt/firefox \ + \ + # Download and install geckodriver + && curl -fL -o /tmp/geckodriver.tar.gz \ + https://github.com/mozilla/geckodriver/releases/download/v${geckodriver_ver}/geckodriver-v${geckodriver_ver}-linux64.tar.gz \ + && tar -xzf /tmp/geckodriver.tar.gz -C /tmp/ \ + && chmod +x /tmp/geckodriver \ + && mv /tmp/geckodriver /usr/local/bin/ \ + \ + # Cleanup unnecessary stuff + && apt-get purge -y --auto-remove \ + -o APT::AutoRemove::RecommendsImportant=false \ + $toolDeps \ + && rm -rf /var/lib/apt/lists/* \ + /tmp/* EXPOSE 4444 +ENTRYPOINT ["geckodriver"] + +CMD ["--binary=/opt/firefox/firefox", "--log=debug", "--host=0.0.0.0"] + + + diff --git a/LICENSE.md b/LICENSE.md index 0cb1cc6..8852bcc 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,21 +1,25 @@ The MIT License (MIT) +===================== -Copyright (c) 2018 Instrumentisto Team, +Copyright © 2019 Instrumentisto Team, https://github.com/instrumentisto -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile index 2fc40a2..1e1f929 100644 --- a/Makefile +++ b/Makefile @@ -11,42 +11,57 @@ # make release -IMAGE_NAME := instrumentisto/geckodriver -VERSION ?= 69.0 -FIREFOX_VERSION ?= 69.0 -GECKODRIVER_VERSION ?= 0.25.0 -TAGS ?= 69.0,latest - - comma := , eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\ $(findstring $(2),$(1))),1) +FIREFOX_VER ?= 69.0 +GECKODRIVER_VER ?= 0.25.0 + +IMAGE_NAME := instrumentisto/geckodriver +TAGS ?= $(FIREFOX_VER)-driver$(GECKODRIVER_VER)-debian-buster \ + $(FIREFOX_VER)-driver$(GECKODRIVER_VER)-debian \ + $(FIREFOX_VER)-driver$(GECKODRIVER_VER) \ + $(FIREFOX_VER)-debian-buster \ + $(FIREFOX_VER)-debian \ + $(FIREFOX_VER) \ + debian-buster \ + debian \ + latest +VERSION ?= $(word 1,$(subst $(comma), ,$(TAGS))) + # Build Docker image. # # Usage: -# make image [VERSION=] [no-cache=(no|yes)] +# make image [tag=($(VERSION)|)] [no-cache=(no|yes)] +# [FIREFOX_VER=] +# [GECKODRIVER_VER=] + +image-tag = $(if $(call eq,$(tag),),$(VERSION),$(tag)) image: docker build --network=host --force-rm \ - --build-arg firefox_ver=$(FIREFOX_VERSION) \ - --build-arg geckodriver_ver=$(GECKODRIVER_VERSION) \ $(if $(call eq,$(no-cache),yes),--no-cache --pull,) \ - -t $(IMAGE_NAME):$(VERSION) . + --build-arg firefox_ver=$(FIREFOX_VER) \ + --build-arg geckodriver_ver=$(GECKODRIVER_VER) \ + -t $(IMAGE_NAME):$(image-tag) . # Tag Docker image with given tags. # # Usage: -# make tags [VERSION=] -# [TAGS=[,...]] +# make tags [for=($(VERSION)|)] +# [tags=($(TAGS)|[,...])] + +tags-for = $(if $(call eq,$(for),),$(VERSION),$(for)) +tags-tags = $(if $(call eq,$(tags),),$(TAGS),$(tags)) tags: - $(foreach tag, $(subst $(comma), ,$(TAGS)),\ - $(call docker.tag.do,$(VERSION),$(tag))) + $(foreach tag, $(subst $(comma), ,$(tags-tags)),\ + $(call tags.do,$(tags-for),$(tag))) define tags.do $(eval from := $(strip $(1))) $(eval to := $(strip $(2))) @@ -58,11 +73,13 @@ endef # Manually push Docker images to Docker Hub. # # Usage: -# make push [TAGS=[,...]] +# make push [tags=($(TAGS)|[,...])] + +push-tags = $(if $(call eq,$(tags),),$(TAGS),$(tags)) push: - $(foreach tag, $(subst $(comma), ,$(TAGS)),\ - $(call docker.push.do, $(tag))) + $(foreach tag, $(subst $(comma), ,$(push-tags)),\ + $(call push.do, $(tag))) define push.do $(eval tag := $(strip $(1))) docker push $(IMAGE_NAME):$(tag) @@ -73,10 +90,17 @@ endef # Make manual release of Docker images to Docker Hub. # # Usage: -# make release [VERSION=] [no-cache=(no|yes)] -# [TAGS=[,...]] +# make release [tag=($(VERSION)|)] [no-cache=(no|yes)] +# [tags=($(TAGS)|[,...])] +# [FIREFOX_VER=] +# [GECKODRIVER_VER=] -release: | image tags push +release: + @make image tag=$(tag) no-cache=$(no-cache) \ + FIREFOX_VER=$(FIREFOX_VER) \ + GECKODRIVER_VER=$(GECKODRIVER_VER) + @make tags for=$(tag) tags=$(tags) + @make push tags=$(tags) @@ -89,14 +113,17 @@ release: | image tags push # http://windsock.io/automated-docker-image-builds-with-multiple-tags # # Usage: -# make post-push-hook [TAGS=[,...]] +# make post-push-hook [tags=($(TAGS)|[,...])] +# [out=(hooks/post_push|)] + +post-push-hook-tags = $(if $(call eq,$(tags),),$(TAGS),$(tags)) post-push-hook: @mkdir -p hooks/ docker run --rm -i -v "$(PWD)/post_push.tmpl.php":/post_push.php:ro \ php:alpine php -f /post_push.php -- \ - --image_tags='$(TAGS)' \ - > hooks/post_push + --image_tags='$(post-push-hook-tags)' \ + > $(if $(call eq,$(out),),hooks/post_push,$(out)) @@ -106,13 +133,16 @@ post-push-hook: # https://github.com/bats-core/bats-core # # Usage: -# make test [VERSION=] +# make test [tag=($(VERSION)|)] + +test-tag = $(if $(call eq,$(tag),),$(VERSION),$(tag)) test: ifeq ($(wildcard node_modules/.bin/bats),) @make deps.bats endif - IMAGE=$(IMAGE_NAME):$(VERSION) node_modules/.bin/bats test/suite.bats + IMAGE=$(IMAGE_NAME):$(test-tag) \ + node_modules/.bin/bats test/suite.bats @@ -122,7 +152,7 @@ endif # make deps.bats deps.bats: - docker run --rm -v "$(PWD)":/app -w /app \ + docker run --rm --network=host -v "$(PWD)":/app -w /app \ node:alpine \ yarn install --non-interactive --no-progress diff --git a/README.md b/README.md index e461d61..2229c8d 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,33 @@ -Geckodriver Docker image -=============================== +geckodriver Docker image +======================== -[![GitHub release](https://img.shields.io/github/release/instrumentisto/geckodriver-docker-image.svg)](https://hub.docker.com/r/instrumentisto/geckodriver/tags) [![Build Status](https://travis-ci.org/instrumentisto/geckodriver-docker-image.svg?branch=master)](https://travis-ci.org/instrumentisto/geckodriver-docker-image) [![Docker Pulls](https://img.shields.io/docker/pulls/instrumentisto/geckodriver.svg)](https://hub.docker.com/r/instrumentisto/geckodriver) +[![Build Status](https://travis-ci.org/instrumentisto/geckodriver-docker-image.svg?branch=master)](https://travis-ci.org/instrumentisto/geckodriver-docker-image) [![Docker Pulls](https://img.shields.io/docker/pulls/instrumentisto/geckodriver.svg)](https://hub.docker.com/r/instrumentisto/geckodriver) -## What is Geckodriver Docker image? +## Supported tags and respective `Dockerfile` links + +- `69.0-driver0.25.0-debian-buster`, `69.0-driver0.25.0-debian`, `69.0-driver0.25.0`, `69.0-debian-buster`, `69.0-debian`, `69.0`, `debian-buster`, `debian`, `latest` [(Dockerfile)][101] + + + + +## What is geckodriver? + +[geckodriver] is a proxy for using W3C [WebDriver] compatible clients to interact with Gecko-based browsers. + +This program provides the HTTP API described by the [WebDriver protocol] to communicate with Gecko browsers, such as [Firefox]. It translates calls into the [Marionette remote protocol] by acting as a proxy between the local and remote ends. + +This image bundles [geckodriver] with [Firefox] and is suitable for running headless tests. + +[Marionette remote protocol]: https://firefox-source-docs.mozilla.org/testing/marionette +[WebDriver]: https://developer.mozilla.org/en-US/docs/Web/WebDriver +[WebDriver protocol]: https://w3c.github.io/webdriver/#protocol + +> [firefox-source-docs.mozilla.org/testing/geckodriver](https://firefox-source-docs.mozilla.org/testing/geckodriver) + -This image bundles Geckodriver with Firefox and is suitable for running headless tests. ## How to use this image @@ -17,25 +36,20 @@ This image bundles Geckodriver with Firefox and is suitable for running headless docker run -d -p 4444:4444 instrumentisto/geckodriver ``` -After that you can connect to Geckodriver that will be running on `127.0.0.1:4444`. Only headless mode is supported. - -Consider running image with `--network=host` if you want to run tests on local server. - -Consider running image with increased shared memory size (`--shm-size 2g`), otherwise you may experience unexpected Firefox crashes. +After that you can connect to [geckodriver] that is listening on `127.0.0.1:4444`. Only headless mode is supported. +Consider using `--network=host` option for running image if you want to run tests on local server. -## Image versions - -Image version corresponds to Firefox version used. +Consider to increase shared memory size (`--shm-size 2g` option), otherwise you may experience unexpected [Firefox] crashes. ## License -Firefox and Geckodriver are licensed under [Mozilla Public License][91]. +[Firefox] and [geckodriver] are licensed under [Mozilla Public License]. -Geckodriver Docker image is licensed under [MIT license][92]. +[geckodriver] Docker image is licensed under [MIT license][2]. @@ -49,6 +63,12 @@ If you have any problems with or questions about this image, please contact us t + +[Firefox]: https://www.mozilla.org/firefox +[geckodriver]: https://github.com/mozilla/geckodriver +[Mozilla Public License]: https://www.mozilla.org/en-US/MPL/2.0 + [1]: https://github.com/instrumentisto/geckodriver-docker-image/issues -[91]: https://www.mozilla.org/en-US/MPL/2.0/ -[92]: https://github.com/instrumentisto/geckodriver-docker-image/blob/master/LICENSE.md +[2]: https://github.com/instrumentisto/geckodriver-docker-image/blob/master/LICENSE.md + +[101]: https://github.com/instrumentisto/geckodriver-docker-image/blob/master/Dockerfile diff --git a/hooks/post_push b/hooks/post_push index 6e171fd..ad9f317 100644 --- a/hooks/post_push +++ b/hooks/post_push @@ -9,7 +9,7 @@ tagStart=$(expr index "$IMAGE_NAME" :) repoName=${IMAGE_NAME:0:tagStart-1} # Tag and push image for each additional tag -for tag in {69.0,latest}; do +for tag in {69.0-driver0.25.0-debian-buster,69.0-driver0.25.0-debian,69.0-driver0.25.0,69.0-debian-buster,69.0-debian,69.0,debian-buster,debian,latest}; do docker tag $IMAGE_NAME ${repoName}:${tag} docker push ${repoName}:${tag} done diff --git a/post_push.tmpl.php b/post_push.tmpl.php index 2c21034..bd58290 100644 --- a/post_push.tmpl.php +++ b/post_push.tmpl.php @@ -10,7 +10,7 @@ repoName=${IMAGE_NAME:0:tagStart-1} # Tag and push image for each additional tag -for tag in {}; do +for tag in {}; do docker tag $IMAGE_NAME ${repoName}:${tag} docker push ${repoName}:${tag} done diff --git a/test/suite.bats b/test/suite.bats index 01ff020..d6fb13d 100644 --- a/test/suite.bats +++ b/test/suite.bats @@ -2,7 +2,9 @@ @test "post_push hook is up-to-date" { - run sh -c "cat Makefile | grep 'TAGS ?= ' | cut -d ' ' -f 3" + run sh -c "make post-push-hook out=/dev/stdout | grep 'for tag in' \ + | cut -d '{' -f 2 \ + | cut -d '}' -f 1" [ "$status" -eq 0 ] [ ! "$output" = '' ] expected="$output" @@ -17,8 +19,19 @@ [ "$actual" = "$expected" ] } + +@test "Firefox is installed" { + run docker run --rm --entrypoint sh $IMAGE -c 'test -f /opt/firefox/firefox' + [ "$status" -eq 0 ] +} + +@test "Firefox runs ok" { + run docker run --rm --entrypoint sh $IMAGE -c '/opt/firefox/firefox --help' + [ "$status" -eq 0 ] +} + @test "Firefox has correct version" { - run sh -c "cat Makefile | grep 'FIREFOX_VERSION ?= ' | cut -d ' ' -f 3" + run sh -c "cat Makefile | grep 'FIREFOX_VER ?= ' | cut -d ' ' -f 3" [ "$status" -eq 0 ] [ ! "$output" = '' ] expected="$output" @@ -32,21 +45,28 @@ [ "$actual" = "$expected" ] } -@test "Geckodriver has correct version" { - run sh -c "cat Makefile | grep 'GECKODRIVER_VERSION ?= ' | cut -d ' ' -f 3" + +@test "geckodriver is installed" { + run docker run --rm --entrypoint sh $IMAGE -c 'which geckodriver' + [ "$status" -eq 0 ] +} + +@test "geckodriver runs ok" { + run docker run --rm --entrypoint sh $IMAGE -c 'geckodriver --help' + [ "$status" -eq 0 ] +} + +@test "geckodriver has correct version" { + run sh -c "cat Makefile | grep 'GECKODRIVER_VER ?= ' | cut -d ' ' -f 3" [ "$status" -eq 0 ] [ ! "$output" = '' ] expected="$output" - echo "$expected" - run docker run --rm --entrypoint sh $IMAGE -c \ "geckodriver -V | grep -m 1 geckodriver | cut -d ' ' -f2" [ "$status" -eq 0 ] [ ! "$output" = '' ] actual="$output" - echo "$actual" - [ "$actual" = "$expected" ] }