From cedcc3fc9f7ac0ec9ccd9f0fece1b5fbd9843e3e Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 23 Mar 2021 09:37:18 +0100 Subject: [PATCH 1/2] Started build script --- Makefile | 6 +++--- build | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100755 build diff --git a/Makefile b/Makefile index 603ad5d..e878d28 100644 --- a/Makefile +++ b/Makefile @@ -16,11 +16,11 @@ release: .PHONY: release image: Dockerfile - @ docker build -t '$(IMAGE):$(TAG)' . + @ bash ./build '$(IMAGE)' .PHONY: image -push: image - @ docker push '$(IMAGE):$(TAG)' +push: + @ bash ./build '$(IMAGE)' push .PHONY: push # Run diff --git a/build b/build new file mode 100755 index 0000000..480b6f1 --- /dev/null +++ b/build @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Simple guard to check input args +[[ $# -eq 1 ]] || [[ $# -eq 2 ]] || { + >&2 echo "Usage: ./build IMAGE [ACTION]" + exit 1 +} + +# Extract current version from Cargo.toml & get current branch +patch_version="$(grep -Po '(?<=version = ").*(?=")' Cargo.toml | head -n1)" +major_version="$(echo "$patch_version" | + sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\1/')" +minor_version="$(echo "$patch_version" | + sed -E 's/([0-9]+).([0-9]+).([0-9]+)/\1.\2/')" +branch="$(git branch --show-current)" + +if [[ "$branch" = "master" ]]; then + tags=("$patch_version" "$minor_version" "$major_version" ) + +elif [[ "$branch" = "develop" ]]; then + tags=("$patch_version-dev" "$minor_version-dev" "$major_version-dev" ) + +else + tags=("$branch") + +fi + +tag_flags=() + +for tag in "${tags[@]}"; do + tag_flags+=("-t '$1:$tag'") + +done + +# Run the actual build command +docker build $tag_flags . + +if [[ "$2" = push ]]; then + for tag in "${tags[@]}"; do + docker push "$1:$tag" + done + + elif [[ "$2" = run ]]; then + docker run \ + --rm \ + --interactive \ + --tty \ + --publish 8000:8000 \ + "$1:$tags" +fi From ab94583e62fae1db9f300b702335057260b52525 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 23 Mar 2021 10:42:20 +0100 Subject: [PATCH 2/2] Fixed wrinkles in build script --- Cargo.lock | 20 ++++++++++---------- Makefile | 6 ++---- build | 9 +++++++-- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 85dbcb8..d7b6fcf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -313,6 +313,16 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "fej" +version = "0.0.1" +dependencies = [ + "reqwest", + "rocket", + "rocket_contrib", + "serde", +] + [[package]] name = "filetime" version = "0.2.14" @@ -1254,16 +1264,6 @@ dependencies = [ "unicode-xid 0.1.0", ] -[[package]] -name = "rust-api" -version = "0.1.0" -dependencies = [ - "reqwest", - "rocket", - "rocket_contrib", - "serde", -] - [[package]] name = "rustc_version" version = "0.2.3" diff --git a/Makefile b/Makefile index e878d28..4017a77 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,4 @@ IMAGE := chewingbever/fej -TAG := 0.0.1-dev -shell := /bin/bash all: debug @@ -16,11 +14,11 @@ release: .PHONY: release image: Dockerfile - @ bash ./build '$(IMAGE)' + @ ./build '$(IMAGE)' .PHONY: image push: - @ bash ./build '$(IMAGE)' push + @ ./build '$(IMAGE)' push .PHONY: push # Run diff --git a/build b/build index 480b6f1..85adacf 100755 --- a/build +++ b/build @@ -15,7 +15,7 @@ minor_version="$(echo "$patch_version" | branch="$(git branch --show-current)" if [[ "$branch" = "master" ]]; then - tags=("$patch_version" "$minor_version" "$major_version" ) + tags=("$patch_version" "$minor_version" "$major_version" "latest" ) elif [[ "$branch" = "develop" ]]; then tags=("$patch_version-dev" "$minor_version-dev" "$major_version-dev" ) @@ -28,7 +28,7 @@ fi tag_flags=() for tag in "${tags[@]}"; do - tag_flags+=("-t '$1:$tag'") + tag_flags+=("-t $1:$tag") done @@ -36,6 +36,11 @@ done docker build $tag_flags . if [[ "$2" = push ]]; then + [[ "$branch" =~ ^develop|master$ ]] || { + >&2 echo "You can only push from develop or master." + exit 2 + } + for tag in "${tags[@]}"; do docker push "$1:$tag" done