forked from postalserver/postal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docker): add tools for generating docker images
- Loading branch information
Showing
6 changed files
with
197 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,3 @@ node_modules | |
Dockerfile | ||
vendor/bundle | ||
.cache | ||
docker/* | ||
PotamusFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
exports: | ||
- name: CHANGELOG.md | ||
formatter: markdown | ||
options: | ||
title: CHANGELOG | ||
description: This file contains all the latest changes and updates to Postal. | ||
sections: | ||
- title: Features | ||
types: [feat] | ||
- title: Bug Fixes | ||
types: [fix] | ||
# | ||
# There are additional options you can define, check out the README for details. | ||
# https://github.com/krystal/schmersion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# ============================================================================== | ||
# Welcome to the Makefile | ||
# ============================================================================== | ||
# | ||
# This Makefile contains a series of tasks which can help with building, testing | ||
# and working with the app. The following tasks are available to you: | ||
# | ||
# Image building & releasing actions: | ||
# | ||
# make docker-build - Builds a production Docker image. | ||
# make docker-ci-build - Builds an image without any asset compilation, | ||
# ideal for running test suites and similar tasks. | ||
# make docker-image - Builds a production Docker image and tags it as | ||
# appropriate based on the current branch & tag. | ||
# make docker-release - Builds a production Docker image and uploads to the | ||
# registry. | ||
# | ||
|
||
# ============================================================================== | ||
# Configuration | ||
# ============================================================================== | ||
|
||
# Docker image name to release the production image as. | ||
DOCKER_IMAGE := postalhq/postal | ||
|
||
# Path to bundle config | ||
BUNDLE_CONFIG ?= $(HOME)/.bundle/config | ||
|
||
# Detect if a tty is available | ||
TTY := $(shell [ -t 0 ] && echo 1) | ||
|
||
# Tag names | ||
DOCKER_TAG_NAME ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null) | ||
DOCKER_TAG_VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null) | ||
|
||
ifeq ($(DOCKER_TAG_NAME),master) | ||
DOCKER_TAG_NAME = latest | ||
endif | ||
|
||
ifeq ($(DOCKER_TAG_NAME),main) | ||
DOCKER_TAG_NAME = latest | ||
endif | ||
|
||
# Version string to use | ||
VERSION ?= $(DOCKER_TAG_VERSION) | ||
ifeq ($(VERSION),) | ||
VERSION = $(shell git describe --tags 2>/dev/null) | ||
endif | ||
|
||
ifeq ($(VERSION),) | ||
VERSION = 0.0.0-dev | ||
endif | ||
|
||
# ============================================================================== | ||
# Image Building | ||
# ============================================================================== | ||
|
||
DOCKER_BUILD_CMD = DOCKER_BUILDKIT=1 docker \ | ||
build $(if $(TTY),,--progress plain) \ | ||
--build-arg VERSION=$(VERSION) \ | ||
--secret "id=bundle_config,src=$(BUNDLE_CONFIG)" \ | ||
. | ||
|
||
DOCKER_CI_BUILD_CMD = $(DOCKER_BUILD_CMD) --target=ci | ||
|
||
.PHONY: docker-build | ||
docker-build: | ||
$(DOCKER_BUILD_CMD) | ||
|
||
.PHONY: docker-ci-build | ||
docker-ci-build: | ||
$(DOCKER_CI_BUILD_CMD) | ||
|
||
# ============================================================================== | ||
# Image Tagging | ||
# ============================================================================== | ||
|
||
.PHONY: docker-image | ||
docker-image: docker-build | ||
$(eval IMAGE := $(shell $(DOCKER_BUILD_CMD) -q)) | ||
ifeq ($(DOCKER_TAG_NAME),latest) | ||
docker tag "$(IMAGE)" "$(DOCKER_IMAGE):$(DOCKER_TAG_NAME)" | ||
endif | ||
|
||
# ============================================================================== | ||
# Image Releasing | ||
# ============================================================================== | ||
|
||
.PHONY: docker-release | ||
docker-release: docker-image | ||
ifeq ($(DOCKER_TAG_NAME),latest) | ||
docker push "$(DOCKER_IMAGE):$(DOCKER_TAG_NAME)" | ||
endif | ||
ifneq ($(DOCKER_TAG_VERSION),) | ||
docker tag "$(DOCKER_IMAGE):$(DOCKER_TAG_NAME)" \ | ||
"$(DOCKER_IMAGE):$(DOCKER_TAG_VERSION)" && \ | ||
docker push "$(DOCKER_IMAGE):$(DOCKER_TAG_VERSION)" | ||
endif |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/sh | ||
[ -n "$DEBUG" ] && set -x | ||
|
||
check_http() { | ||
wget -T 1 -S -q -O - "$1" 2>&1 | head -1 | | ||
head -1 | grep -E 'HTTP.+\s2\d{2}' >/dev/null 2>&1 | ||
return $? | ||
} | ||
|
||
check_tcp() { | ||
host="$(echo "$1" | cut -d: -f1)" | ||
port="$(echo "$1" | cut -d: -f2)" | ||
if [ -z "${host}" ] || [ -z "${port}" ]; then | ||
echo "TCP target ${1} is not in \"<host>:<port>\" format" >&2 | ||
exit 2 | ||
fi | ||
|
||
nc -z -w1 "$host" "$port" >/dev/null 2>&1 | ||
return $? | ||
} | ||
|
||
wait_for() { | ||
type="$1" | ||
uri="$2" | ||
timeout="${3:-30}" | ||
|
||
seconds=0 | ||
while [ "$seconds" -lt "$timeout" ] && ! "check_${type}" "$uri"; do | ||
if [ "$seconds" -lt "1" ]; then | ||
printf "Waiting for %s ." "$uri" | ||
else | ||
printf . | ||
fi | ||
seconds=$((seconds + 1)) | ||
sleep 1 | ||
done | ||
|
||
if [ "$seconds" -lt "$timeout" ]; then | ||
if [ "$seconds" -gt "0" ]; then | ||
echo " up!" | ||
fi | ||
else | ||
echo " FAIL" | ||
echo "ERROR: unable to connect to: $uri" >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
if [ -n "$WAIT_FOR_TARGETS" ]; then | ||
uris="$(echo "$WAIT_FOR_TARGETS" | sed -e 's/\s+/\n/g' | uniq)" | ||
for uri in $uris; do | ||
if echo "$uri" | grep -E '^https?:https://.*' >/dev/null 2>&1; then | ||
wait_for "http" "$uri" "$WAIT_FOR_TIMEOUT" | ||
else | ||
wait_for "tcp" "$uri" "$WAIT_FOR_TIMEOUT" | ||
fi | ||
done | ||
fi | ||
|
||
exec "$@" |