build_and_push.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing,
  13. # software distributed under the License is distributed on an
  14. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. # KIND, either express or implied. See the License for the
  16. # specific language governing permissions and limitations
  17. # under the License.
  18. set -euo pipefail
  19. DOCKERHUB_USER=${DOCKERHUB_USER:="apache"}
  20. readonly DOCKERHUB_USER
  21. DOCKERHUB_REPO=${DOCKERHUB_REPO:="airflow"}
  22. readonly DOCKERHUB_REPO
  23. PGBOUNCER_VERSION="1.14.0"
  24. readonly PGBOUNCER_VERSION
  25. AIRFLOW_PGBOUNCER_VERSION="2021.04.28"
  26. readonly AIRFLOW_PGBOUNCER_VERSION
  27. COMMIT_SHA=$(git rev-parse HEAD)
  28. readonly COMMIT_SHA
  29. TAG="${DOCKERHUB_USER}/${DOCKERHUB_REPO}:airflow-pgbouncer-${AIRFLOW_PGBOUNCER_VERSION}-${PGBOUNCER_VERSION}"
  30. readonly TAG
  31. function center_text() {
  32. columns=$(tput cols || echo 80)
  33. printf "%*s\n" $(( (${#1} + columns) / 2)) "$1"
  34. }
  35. cd "$( dirname "${BASH_SOURCE[0]}" )" || exit 1
  36. center_text "Building image"
  37. docker build . \
  38. --pull \
  39. --build-arg "PGBOUNCER_VERSION=${PGBOUNCER_VERSION}" \
  40. --build-arg "AIRFLOW_PGBOUNCER_VERSION=${AIRFLOW_PGBOUNCER_VERSION}"\
  41. --build-arg "COMMIT_SHA=${COMMIT_SHA}" \
  42. --tag "${TAG}"
  43. center_text "Checking image"
  44. docker run --rm "${TAG}" pgbouncer --version
  45. echo Image labels:
  46. docker inspect "${TAG}" --format '{{ json .ContainerConfig.Labels }}' | python3 -m json.tool
  47. center_text "Pushing image"
  48. docker push "${TAG}"