From 5ab5c7c24305b426b26778c92b17e711a269779e Mon Sep 17 00:00:00 2001 From: 1138-4EB <1138-4EB@users.noreply.github.com> Date: Mon, 6 Aug 2018 00:37:16 +0100 Subject: [PATCH] add docker-credential-pass to dev img and use it in travis --- .travis.yml | 11 ++++++----- build/docker_login.sh | 27 +++++++++++++++++++++++++++ dockerfiles/dev | 11 +++++++++-- 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100755 build/docker_login.sh diff --git a/.travis.yml b/.travis.yml index 27334cc1..7dc6b578 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,14 +6,15 @@ addons: apt: packages: - docker-ce + - pass env: global: - USE_DOCKER="true" - WDIR=/go/src/github.com/filebrowser/filebrowser stages: -- lint -- test -- release + - lint + - test + - release cache: directories: - vendor @@ -30,7 +31,7 @@ jobs: script: - cp dockerfiles/filebrowser Dockerfile - docker build -t filebrowser/filebrowser . - - echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin + - ./build/docker_login.sh - docker push filebrowser/filebrowser - docker logout on: @@ -40,7 +41,7 @@ jobs: - stage: release script: - cp dockerfiles/filebrowser Dockerfile - - echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin + - ./build/docker_login.sh - docker run --rm -itv $(pwd):$WDIR -v /var/run/docker.sock:/var/run/docker.sock filebrowser/dev goreleaser - docker logout if: tag IS present diff --git a/build/docker_login.sh b/build/docker_login.sh new file mode 100755 index 00000000..fedeaf5a --- /dev/null +++ b/build/docker_login.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +set -e + +# init key for pass +gpg --batch --gen-key <<-EOF +%echo Generating a standard key +Key-Type: DSA +Key-Length: 1024 +Subkey-Type: ELG-E +Subkey-Length: 1024 +Name-Real: Meshuggah Rocks +Name-Email: meshuggah@example.com +Expire-Date: 0 +# Do a commit here, so that we can later print "done" :-) +%commit +%echo done +EOF + +key=$(gpg --no-auto-check-trustdb --list-secret-keys | grep ^sec | cut -d/ -f2 | cut -d" " -f1) +pass init $key + +if [ "$(command -v docker-credential-pass)" = "" ]; then + docker run --rm -itv /usr/local/bin:/src filebrowser/dev sh -c "cp /go/bin/docker-credential-pass /src" +fi + +echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin diff --git a/dockerfiles/dev b/dockerfiles/dev index 0761a949..b6c3cc57 100644 --- a/dockerfiles/dev +++ b/dockerfiles/dev @@ -23,5 +23,12 @@ RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/reposit chmod +x /go/bin/dep && \ curl -sL https://git.io/goreleaser -o /go/bin/goreleaser && \ chmod +x /go/bin/goreleaser && \ - curl -fsSL https://download.docker.com/linux/static/edge/x86_64/docker-18.05.0-ce.tgz | tar xvz --strip-components=1 docker/docker -C /usr/local/bin && \ - chmod +x /usr/local/bin/docker + curl -fsSL https://download.docker.com/linux/static/edge/x86_64/docker-18.05.0-ce.tgz | tar xvz --strip-components=1 docker/docker -C /go/bin && \ + chmod +x /go/bin/docker && \ + curl -fsSL $( \ + curl -s https://api.github.com/repos/docker/docker-credential-helpers/releases/latest \ + | grep "browser_download_url.*pass-.*-amd64" \ + | cut -d : -f 2,3 \ + | tr -d \" \ + ) | tar xv -C /go/bin && \ + chmod + /go/bin/docker-credential-pass