-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
99 lines (82 loc) · 3.17 KB
/
Makefile
File metadata and controls
99 lines (82 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
.PHONY: all auth help image name publish tag vars version
ALPINE_VERSION?=3.23
BUNDLER_VERSION?=$(shell tail -1 Gemfile.lock | tr -d ' ')
RUBY_VERSION?=$(shell cat .ruby-version)
ACCOUNT?=$(shell aws sts get-caller-identity | jq -r .Account)
AWS_REGION?=eu-west-1
ECR?=${ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com
GPR_OWNER?=epimorphics
NAME?=$(shell awk -F: '$$1=="name" {print $$2}' deployment.yaml | sed -e 's/[[:blank:]]//g')
PAT?=$(shell read -p 'Github access token:' TOKEN; echo $$TOKEN)
SHORTNAME?=$(shell echo ${NAME} | cut -f2 -d/)
STAGE?=dev
RAILS_RELATIVE_URL_ROOT?=/app/ppd
BRANCH:=$(shell git rev-parse --abbrev-ref HEAD)
COMMIT=$(shell git rev-parse --short HEAD)
VERSION?=$(shell /usr/bin/env ruby -e 'require "./app/lib/version" ; puts Version::VERSION')
TAG?=$(shell printf '%s_%s_%08d' ${VERSION} ${COMMIT} ${GITHUB_RUN_NUMBER})
IMAGE?=${NAME}/${STAGE}
REPO?=${ECR}/${IMAGE}
BUNDLE_CFG=.bundle/config
BUNDLE=./bin/bundle
GITHUB_TOKEN=.github-token
${BUNDLE_CFG}: ${GITHUB_TOKEN}
@${BUNDLE} config set --local rubygems.pkg.github.com ${GPR_OWNER}:`cat ${GITHUB_TOKEN}`
${GITHUB_TOKEN}:
@echo ${PAT} > ${GITHUB_TOKEN}
all: image ## Default target: build the Docker image
auth: ${GITHUB_TOKEN} ${BUNDLE_CFG} ## Set up authentication for GitHub and Bundler
@echo "Authentication set up for GitHub and Bundler."
help: ## Display this message
@echo "Available make targets:"
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-20s %s\n", $$1, $$2}'
@echo ""
ifdef AWS_PROFILE
@echo "Environment variables (optional: all variables have defaults):"
@make vars
else
@echo "Warning: AWS_PROFILE is not set. AWS CLI commands may fail."
@echo "Re-run with AWS_PROFILE set to see all variables."
endif
image: auth ## Build the Docker image
@echo Building ${REPO}:${TAG} ...
@docker build \
--build-arg ALPINE_VERSION=${ALPINE_VERSION} \
--build-arg RUBY_VERSION=${RUBY_VERSION} \
--build-arg BUNDLER_VERSION=${BUNDLER_VERSION} \
--build-arg RAILS_RELATIVE_URL_ROOT=${RAILS_RELATIVE_URL_ROOT} \
--build-arg VERSION=${VERSION} \
--build-arg git_branch=${BRANCH} \
--build-arg git_commit_hash=${COMMIT} \
--build-arg github_run_number=${GITHUB_RUN_NUMBER} \
--build-arg image_name=${NAME} \
--tag ${REPO}:${TAG} \
.
@echo Done.
name: ## Display the shortname of the application
@echo ${SHORTNAME}
publish: image ## Publish the Docker image to the registry
@echo Publishing image: ${REPO}:${TAG} ...
@docker push ${REPO}:${TAG} 2>&1
@echo Done.
tag: ## Display the Docker image tag
@echo ${TAG}
vars: ## Display build environment variables
@echo "Docker: ${REPO}:${TAG}"
@echo "ACCOUNT = ${ACCOUNT}"
@echo "ALPINE_VERSION = ${ALPINE_VERSION}"
@echo "AWS_REGION = ${AWS_REGION}"
@echo "BUNDLER_VERSION = ${BUNDLER_VERSION}"
@echo "COMMIT = ${COMMIT}"
@echo "ECR = ${ECR}"
@echo "GPR_OWNER = ${GPR_OWNER}"
@echo "NAME = ${NAME}"
@echo "RAILS_RELATIVE_URL_ROOT = ${RAILS_RELATIVE_URL_ROOT}"
@echo "REPO = ${REPO}"
@echo "RUBY_VERSION = ${RUBY_VERSION}"
@echo "SHORTNAME = ${SHORTNAME}"
@echo "STAGE = ${STAGE}"
@echo "TAG = ${TAG}"
@echo "VERSION = ${VERSION}"
version: ## Display the application version
@echo ${VERSION}