From 59118cd6a414e2a9991fdb8b0beeb92f70088842 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Thu, 15 Apr 2021 21:02:56 +0200 Subject: [PATCH] Add release script --- README.md | 14 ++- build/api/rr.Dockerfile | 2 +- {front => build/front}/Dockerfile | 0 build/release.sh | 154 ++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 6 deletions(-) rename {front => build/front}/Dockerfile (100%) create mode 100755 build/release.sh diff --git a/README.md b/README.md index ef893b0..7bcd15a 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,19 @@ aims to be the central hub for all public transport information you will need. You can use the app at [cojedzie.pl](https://cojedzie.pl). -# Available cities -For now tricity is the only available data source. - -# Contributing +## Contributing Want to contribute? -# License + +## Roadmap +Co Jedzie is in active development, roadmap of the project can be found on [trello]. This roadmap is regularly updated +and represents current state of the project. Feel free to take a look. + +## License This project is [fair-code](https://faircode.io/) licensed under [MIT with Commons Clause](./LICENSE.md). Basically, Co Jedzie is free and code is available to everyone, but it's not allowed to make money directly with it. Note that data collected from available data sources is licensed by their respective owners, thus it may be available under different terms than the project itself and may require additional permissions to use. + +[trello]: https://trello.com/b/QXqDvmoG/co-jedzie diff --git a/build/api/rr.Dockerfile b/build/api/rr.Dockerfile index 2fc23a0..bcdf906 100644 --- a/build/api/rr.Dockerfile +++ b/build/api/rr.Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.4-alpinpe +FROM php:7.4-alpine LABEL maintainer="Kacper Donat " diff --git a/front/Dockerfile b/build/front/Dockerfile similarity index 100% rename from front/Dockerfile rename to build/front/Dockerfile diff --git a/build/release.sh b/build/release.sh new file mode 100755 index 0000000..62171a4 --- /dev/null +++ b/build/release.sh @@ -0,0 +1,154 @@ +#!/bin/bash + +TAGS=$* +BUILD=$(dirname $0) +ROOT=$BUILD/.. + +REGISTRY="docker.io" +TAGS=() +DRY=0 +PUSH=0 + +BUILT_TAGS=() + +export DOCKER_BUILDKIT=1 + +usage () { + echo "usage: $0 [-h|--help] [-d|--dry] [-r|--registry registry] [-t|--tag tag] [-p|--push] -- images..."; +} + +run () { + if [[ $DRY == 1 ]]; then + echo "$@" + else + "$@" + fi +} + +# usage: build [-d|--default] [-v|--variant variant] +build () { + ARGS=() + IS_DEFAULT=0 + SUFFIX="" + VARIANT="" + + options=$(getopt -l "default,variant:" -o "dv:" -- "$@") + eval set -- "$options" + + while true; + do + case "$1" in + -d|--default) + IS_DEFAULT=1 + shift + ;; + -v|--variant) + VARIANT="$2" + shift 2 + ;; + --) + shift + break + ;; + *) + echo "build: unknown option $1" + exit 1 + esac + done + + IMAGE=$1 + CONTEXT=$2 + shift 2; + + # check for variant + if [[ -z "$VARIANT" ]]; then + ARGS+=("-f" "$BUILD/$IMAGE/Dockerfile") + else + ARGS+=("-f" "$BUILD/$IMAGE/$VARIANT.Dockerfile") + SUFFIX="-$VARIANT" + fi + + for TAG in "${TAGS[@]}"; do + ARGS+=("-t" "$REGISTRY/cojedzie/$IMAGE:$TAG$SUFFIX") + BUILT_TAGS+=("$REGISTRY/cojedzie/$IMAGE:$TAG$SUFFIX") + + if [[ $IS_DEFAULT == 1 ]]; then + ARGS+=("-t" "$REGISTRY/cojedzie/$IMAGE:$TAG") + BUILT_TAGS+=("$REGISTRY/cojedzie/$IMAGE:$TAG") + fi + done + + run docker build $CONTEXT "${ARGS[@]}" "$@" +} + +options=$(getopt -l "help,dry,registry:,tag:,push" -o "hdr:t:p" -- "$@") +eval set -- "$options" + +while true; +do + case "$1" in + -h|--help) + usage + exit 0 + ;; + -t|--tag) + TAGS+=("$2") + shift 2 + ;; + -p|--push) + PUSH=1 + shift + ;; + -r|--registry) + REGISTRY="$2" + shift 2 + ;; + -d|--dry) + DRY=1 + shift + ;; + --) + shift + break; + esac +done + +# set default tags if user have not provided any +if [ ${#TAGS[@]} -eq 0 ]; then + TAGS=("latest") +fi + +if [ $# -eq 0 ]; then + set -- api standalone worker front +fi + +while [ $# -gt 0 ] +do + case "$1" in + api) + build api $ROOT/api/ --variant rr --default + build api $ROOT/api/ --variant fpm + ;; + standalone) + build standalone $ROOT/api/ --variant rr --default + ;; + worker) + build worker $ROOT/api/ + ;; + front) + build front $ROOT/front/ + ;; + *) + >&2 echo "$1 is not a valid image to build" + esac + shift +done + +if [ $PUSH -eq 1 ]; then + for TAG in "${BUILT_TAGS[@]}"; do + docker push $TAG + done +else + echo "Created tags:" + printf " - %s\n" "${BUILT_TAGS[@]}" +fi