From 6090c343e1dcba33e7c322df96f47278ea455433 Mon Sep 17 00:00:00 2001 From: Sameer Naik Date: Sun, 24 May 2020 19:36:09 +0530 Subject: [PATCH] release 3.3-20200524 (#27) * fix heathcheck wget args * update baseimage to ubuntu:focal and apt-cacher to 3.3 Closes #12 #26 * update circleci config * release 3.3-20200524 * fix shellcheck issues --- .circleci/config.yml | 350 ++++++++++++++++++++++++++++++++++----- Dockerfile | 6 +- README.md | 14 +- VERSION | 2 +- docker-compose.yml | 2 +- entrypoint.sh | 4 +- scripts/release-notes.sh | 48 ++++++ 7 files changed, 366 insertions(+), 60 deletions(-) create mode 100755 scripts/release-notes.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 8b3b080..febfe86 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,71 +1,329 @@ -version: 2 -jobs: - build: - working_directory: /workdir - docker: - - image: docker:18.03.0-ce-git - environment: - IMAGE_NAME: "sameersbn/apt-cacher-ng" +version: 2.1 +orbs: + shellcheck: circleci/shellcheck@1.3.16 + docker: circleci/docker@1.0.1 + go: circleci/go@1.1.1 + +commands: + docker-build: + description: | + Build and optionally deploy a Docker images + parameters: + dockerfile: + default: Dockerfile + description: 'Name of dockerfile to use, defaults to Dockerfile' + type: string + extra_build_args: + default: '' + description: > + Extra flags to pass to docker build. For examples, see + https://docs.docker.com/engine/reference/commandline/build + type: string + registry: + default: docker.io + description: | + Comma separated list of registry to use, defaults to docker.io + type: string + image: + description: Name of image to build + type: string + tag: + default: $CIRCLE_SHA1 + description: 'Image tag, defaults to the value of $CIRCLE_SHA1' + type: string + path: + default: . + description: > + Path to the directory containing your Dockerfile and build context, + defaults to . (working directory) + type: string + cache_from: + default: '' + description: > + Comma-separated list of images, images will first be pulled, then passed + as the --cache-from build argument + https://docs.docker.com/engine/reference/commandline/build/ + type: string + no_output_timeout: + default: 10m + description: | + No output timeout for build step + type: string steps: - - checkout + - when: + condition: <> + steps: + - run: + name: Build image for <> + no_output_timeout: <> + command: > + echo "<>" | sed -n 1'p' | tr ',' '\n' | + while read image; do + echo "Pulling ${image}"; + docker pull ${image} || true + done + + docker_tag_args="" + + IFS="," read -ra DOCKER_REGISTRIES \<<< "<< parameters.registry >>" + + for registry in "${DOCKER_REGISTRIES[@]}"; do + IFS="," read -ra DOCKER_TAGS \<<< "<< parameters.tag >>" + + for tag in "${DOCKER_TAGS[@]}"; do + docker_tag_args="$docker_tag_args -t $registry/<>:${tag}" + done + done - - setup_remote_docker: - version: 18.03.1-ce + docker build + <<#parameters.extra_build_args>><><> + \ + --cache-from <> \ + -f <>/<> \ + $docker_tag_args \ + <> + - unless: + condition: <> + steps: + - run: + name: Building image for <> + no_output_timeout: <> + command: > + docker_tag_args="" + IFS="," read -ra DOCKER_REGISTRIES \<<< "<< parameters.registry >>" + + for registry in "${DOCKER_REGISTRIES[@]}"; do + IFS="," read -ra DOCKER_TAGS \<<< "<< parameters.tag >>" + + for tag in "${DOCKER_TAGS[@]}"; do + docker_tag_args="$docker_tag_args -t $registry/<>:${tag}" + done + done + + docker build + <<#parameters.extra_build_args>><><> + \ + -f <>/<> \ + $docker_tag_args \ + <> + + docker-save: + description: | + Save one or more images to a tar archive + parameters: + registry: + default: docker.io + description: | + Comma separated list of registry to use, defaults to docker.io + type: string + image: + description: Name of image to build + type: string + tag: + default: $CIRCLE_SHA1 + description: 'Image tag, defaults to the value of $CIRCLE_SHA1' + type: string + steps: - run: - name: Docker info - command: | - docker version - docker info + name: Save image to tar archive + command: > + docker_images="" + + IFS="," read -ra DOCKER_REGISTRIES \<<< "<< parameters.registry >>" - - restore_cache: - keys: - - cache-{{ .Branch }} + for registry in "${DOCKER_REGISTRIES[@]}"; do + IFS="," read -ra DOCKER_TAGS \<<< "<< parameters.tag >>" + + for tag in "${DOCKER_TAGS[@]}"; do + docker_images="$docker_images $registry/<>:${tag}" + done + done + + mkdir -p ~/docker/ + + docker save -o ~/docker/docker-images.tar $docker_images + - persist_to_workspace: + root: ~/ paths: - - /cache/layers.tar + - docker + docker-load: + description: | + Load tar archive + steps: + - attach_workspace: + at: ~/ - run: - name: Loading docker cache - command: | - if [[ -f /cache/layers.tar ]]; then - docker load -i /cache/layers.tar - fi + name: Load images from tar archive + command: > + docker load -i ~/docker/docker-images.tar - - run: - name: Build docker image - command: | - docker build --cache-from=${IMAGE_NAME} -t ${IMAGE_NAME} . + docker-publish: + description: | + Build and optionally deploy a Docker images + parameters: + pr: + default: '' + type: string + registry: + default: docker.io + description: | + Comma separated list of registry to use, defaults to docker.io + type: string + image: + description: Name of image to build + type: string + tag: + default: $CIRCLE_SHA1 + description: 'Image tag, defaults to the value of $CIRCLE_SHA1' + type: string + steps: + - unless: + condition: <> + steps: + - run: + name: Publish image for <> + command: > + IFS="," read -ra DOCKER_REGISTRIES \<<< "<< parameters.registry >>" + + for registry in "${DOCKER_REGISTRIES[@]}"; do + IFS="," read -ra DOCKER_TAGS \<<< "<< parameters.tag >>" + for tag in "${DOCKER_TAGS[@]}"; do + docker push $registry/<< parameters.image>>:${tag} + done + done + +jobs: + build: + executor: docker/machine + steps: + - checkout + - docker-build: + registry: docker.io,quay.io + image: sameersbn/apt-cacher-ng + tag: ${CIRCLE_TAG:-latest} + cache_from: docker.io/sameersbn/apt-cacher-ng:latest + - docker-save: + registry: docker.io,quay.io + image: sameersbn/apt-cacher-ng + tag: ${CIRCLE_TAG:-latest} + + test: + executor: docker/machine + steps: + - checkout + - docker-load - run: - name: Launching container for testing + name: Update tag in docker-compose.yml command: | - docker network create testnet - docker run --name apt-cacher-ng -d --init --net testnet -p 3142:3142 $IMAGE_NAME - + sed -i "s|image: sameersbn/apt-cacher-ng:.*|image: sameersbn/apt-cacher-ng:${CIRCLE_TAG:-latest}|" docker-compose.yml + - run: + name: Launch apt-cacher-ng container + command: docker-compose up -d --quiet-pull + - run: + name: Wait for bootup + command: sleep 15 + - run: + name: Container info + command: docker ps - run: - name: Testing image + name: Test image command: | - docker run --rm --net testnet appropriate/curl --retry 3 --retry-delay 5 -vLo /dev/null http://apt-cacher-ng:3142/apt-cacher + docker run --network container:$(docker-compose ps -q apt-cacher-ng) \ + curlimages/curl --retry 3 --retry-delay 5 -vLo /dev/null http://apt-cacher-ng:3142/apt-cacher + publish-dockerhub: + executor: docker/machine + steps: + - docker-load + - docker/check: + registry: docker.io + docker-username: DOCKER_LOGIN + docker-password: DOCKER_PASSWORD + - docker-publish: + registry: docker.io + image: sameersbn/apt-cacher-ng + tag: ${CIRCLE_TAG:-latest} + + publish-quay: + executor: docker/machine + steps: + - docker-load + - docker/check: + registry: quay.io + docker-username: DOCKER_LOGIN + docker-password: DOCKER_PASSWORD + - docker-publish: + registry: quay.io + image: sameersbn/apt-cacher-ng + tag: ${CIRCLE_TAG:-latest} + + release: + executor: + name: go/default + tag: '1.14' + steps: + - checkout + - run: + name: Installing github-release tool + command: go get github.com/meterup/github-release - run: - name: Generate docker build image cache + name: Creating github release command: | - mkdir -p /cache - docker save -o /cache/layers.tar ${IMAGE_NAME} - - - save_cache: - key: cache-{{ .Branch }}-{{ epoch }} - paths: - - /cache/layers.tar + PRE_RELEASE=${CIRCLE_TAG/${CIRCLE_TAG%-rc[0-9]*}/} + github-release delete -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -t ${CIRCLE_TAG} 2>/dev/null ||: + ./scripts/release-notes.sh ${CIRCLE_TAG} | github-release release ${PRE_RELEASE:+-p} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -t ${CIRCLE_TAG} -d - + for f in $(find /tmp/dist -type f); do github-release upload -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -t ${CIRCLE_TAG} -n $(basename ${f}) -f ${f} ; done workflows: - version: 2 - build-and-test: + build-test-and-release: jobs: + - shellcheck/check: + name: shellcheck + ignore: SC2086,SC2181,SC2124 + filters: + tags: + only: /^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ - build: + requires: + - shellcheck + filters: + tags: + only: /^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ + - test: + requires: + - build + filters: + tags: + only: /^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ + - publish-dockerhub: + context: dockerhub + requires: + - test filters: branches: - only: /.*/ + only: master + tags: + only: /^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ + - publish-quay: + context: quay + requires: + - test + filters: tags: - only: /.*/ + only: /^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ + branches: + only: master + - release: + context: github + requires: + - publish-dockerhub + - publish-quay + filters: + tags: + only: /^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ + branches: + ignore: /.*/ diff --git a/Dockerfile b/Dockerfile index 6044503..52d6cdf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM ubuntu:bionic-20190612 +FROM ubuntu:focal-20200423 LABEL maintainer="sameer@damagehead.com" -ENV APT_CACHER_NG_VERSION=3.1 \ +ENV APT_CACHER_NG_VERSION=3.3 \ APT_CACHER_NG_CACHE_DIR=/var/cache/apt-cacher-ng \ APT_CACHER_NG_LOG_DIR=/var/log/apt-cacher-ng \ APT_CACHER_NG_USER=apt-cacher-ng @@ -21,7 +21,7 @@ RUN chmod 755 /sbin/entrypoint.sh EXPOSE 3142/tcp HEALTHCHECK --interval=10s --timeout=2s --retries=3 \ - CMD wget -q -t1 -o /dev/null http://localhost:3142/acng-report.html || exit 1 + CMD wget -q -t1 -O /dev/null http://localhost:3142/acng-report.html || exit 1 ENTRYPOINT ["/sbin/entrypoint.sh"] diff --git a/README.md b/README.md index da0d821..5963aa6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Circle CI](https://circleci.com/gh/sameersbn/docker-apt-cacher-ng.svg?style=shield)](https://circleci.com/gh/sameersbn/docker-apt-cacher-ng) [![Docker Repository on Quay.io](https://quay.io/repository/sameersbn/apt-cacher-ng/status "Docker Repository on Quay.io")](https://quay.io/repository/sameersbn/apt-cacher-ng) -# sameersbn/apt-cacher-ng:3.1-3 +# sameersbn/apt-cacher-ng:3.3-20200524 - [Introduction](#introduction) - [Contributing](#contributing) @@ -53,7 +53,7 @@ Automated builds of the image are available on [Dockerhub](https://hub.docker.co > **Note**: Builds are also available on [Quay.io](https://quay.io/repository/sameersbn/apt-cacher-ng) ```bash -docker pull sameersbn/apt-cacher-ng:3.1-3 +docker pull sameersbn/apt-cacher-ng:3.3-20200524 ``` Alternatively you can build the image yourself. @@ -70,7 +70,7 @@ Start Apt-Cacher NG using: docker run --name apt-cacher-ng --init -d --restart=always \ --publish 3142:3142 \ --volume /srv/docker/apt-cacher-ng:/var/cache/apt-cacher-ng \ - sameersbn/apt-cacher-ng:3.1-3 + sameersbn/apt-cacher-ng:3.3-20200524 ``` *Alternatively, you can use the sample [docker-compose.yml](docker-compose.yml) file to start the container using [Docker Compose](https://docs.docker.com/compose/)* @@ -83,7 +83,7 @@ You can customize the launch command of Apt-Cacher NG server by specifying argum docker run --name apt-cacher-ng --init -it --rm \ --publish 3142:3142 \ --volume /srv/docker/apt-cacher-ng:/var/cache/apt-cacher-ng \ - sameersbn/apt-cacher-ng:3.1-3 -h + sameersbn/apt-cacher-ng:3.3-20200524 -h ``` ## Persistence @@ -161,7 +161,7 @@ Using the [Command-line arguments](#command-line-arguments) feature, you can spe docker run --name apt-cacher-ng --init -it --rm \ --publish 3142:3142 \ --volume /srv/docker/apt-cacher-ng:/var/cache/apt-cacher-ng \ - sameersbn/apt-cacher-ng:3.1-3 -e + sameersbn/apt-cacher-ng:3.3-20200524 -e ``` The same can also be achieved on a running instance by visiting the url http://localhost:3142/acng-report.html in the web browser and selecting the **Start Scan and/or Expiration** option. @@ -173,7 +173,7 @@ To upgrade to newer releases: 1. Download the updated Docker image: ```bash - docker pull sameersbn/apt-cacher-ng:3.1-3 + docker pull sameersbn/apt-cacher-ng:3.3-20200524 ``` 2. Stop the currently running image: @@ -193,7 +193,7 @@ To upgrade to newer releases: ```bash docker run --name apt-cacher-ng --init -d \ [OPTIONS] \ - sameersbn/apt-cacher-ng:3.1-3 + sameersbn/apt-cacher-ng:3.3-20200524 ``` ## Shell Access diff --git a/VERSION b/VERSION index 722cfad..8d43509 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1-3 +3.3-20200524 diff --git a/docker-compose.yml b/docker-compose.yml index 5014d21..1d233d9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: '2.2' services: apt-cacher-ng: restart: always - image: sameersbn/apt-cacher-ng:3.1-3 + image: sameersbn/apt-cacher-ng:3.3-20200524 init: true ports: - "3142:3142" diff --git a/entrypoint.sh b/entrypoint.sh index a61c6c5..1e9633c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -27,7 +27,7 @@ create_log_dir if [[ ${1:0:1} = '-' ]]; then EXTRA_ARGS="$@" set -- -elif [[ ${1} == apt-cacher-ng || ${1} == $(which apt-cacher-ng) ]]; then +elif [[ ${1} == apt-cacher-ng || ${1} == $(command -v apt-cacher-ng) ]]; then EXTRA_ARGS="${@:2}" set -- fi @@ -35,7 +35,7 @@ fi # default behaviour is to launch apt-cacher-ng if [[ -z ${1} ]]; then exec start-stop-daemon --start --chuid ${APT_CACHER_NG_USER}:${APT_CACHER_NG_USER} \ - --exec $(which apt-cacher-ng) -- -c /etc/apt-cacher-ng ${EXTRA_ARGS} + --exec "$(command -v apt-cacher-ng)" -- -c /etc/apt-cacher-ng ${EXTRA_ARGS} else exec "$@" fi diff --git a/scripts/release-notes.sh b/scripts/release-notes.sh new file mode 100755 index 0000000..15430dc --- /dev/null +++ b/scripts/release-notes.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env sh + +RELEASE=${GIT_TAG:-$1} + +if [ -z "${RELEASE}" ]; then + echo "Usage:" + echo "./scripts/release-notes.sh v0.1.0" + exit 1 +fi + +if ! git rev-list ${RELEASE} >/dev/null 2>&1; then + echo "${RELEASE} does not exist" + exit +fi + +PREV_RELEASE=${PREV_RELEASE:-$(git describe --tags --abbrev=0 ${RELEASE}^)} +PREV_RELEASE=${PREV_RELEASE:-$(git rev-list --max-parents=0 ${RELEASE}^)} +NOTABLE_CHANGES=$(git cat-file -p ${RELEASE} | sed '/-----BEGIN PGP SIGNATURE-----/,//d' | tail -n +6) +CHANGELOG=$(git log --no-merges --pretty=format:'- [%h] %s (%aN)' ${PREV_RELEASE}..${RELEASE}) +if [ $? -ne 0 ]; then + echo "Error creating changelog" + exit 1 +fi + +cat <