-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
121 lines (98 loc) · 3.39 KB
/
Makefile
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
.PHONY: assets check clean image lint publish realclean run tag test vars
ACCOUNT?=$(shell aws sts get-caller-identity | jq -r .Account)
ALPINE_VERSION?=3.20
AWS_REGION?=eu-west-1
BUNDLER_VERSION?=$(shell tail -1 Gemfile.lock | tr -d ' ')
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)
PORT?=3002
RUBY_VERSION?=$(shell cat .ruby-version)
SHORTNAME?=$(shell echo ${NAME} | cut -f2 -d/)
STAGE?=dev
API_SERVICE_URL?=http://data-api:8080
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})
${TAG}:
@echo ${TAG}
IMAGE?=${NAME}/${STAGE}
REPO?=${ECR}/${IMAGE}
GITHUB_TOKEN=.github-token
BUNDLE_CFG=.bundle/config
all: image
${BUNDLE_CFG}: ${GITHUB_TOKEN}
@./bin/bundle config set --local rubygems.pkg.github.com ${GPR_OWNER}:`cat ${GITHUB_TOKEN}`
${GITHUB_TOKEN}:
@echo ${PAT} > ${GITHUB_TOKEN}
assets:
@echo "Installing bundler packages ..."
@./bin/bundle install
@echo "Installing yarn packages ..."
@yarn install
@echo "Cleaning and precompiling static assets ..."
@./bin/rails assets:clean assets:precompile
auth: ${GITHUB_TOKEN} ${BUNDLE_CFG}
check: lint test
@echo "All checks passed."
clean:
@[ -d public/assets ] && ./bin/rails assets:clobber || :
@@ rm -rf bundle coverage log node_modules
image: auth
@echo Building ${NAME}:${TAG} ...
@docker build \
--build-arg ALPINE_VERSION=${ALPINE_VERSION} \
--build-arg RUBY_VERSION=${RUBY_VERSION} \
--build-arg BUNDLER_VERSION=${BUNDLER_VERSION} \
--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 ${NAME}:${TAG} \
.
@echo Done.
lint: assets
@./bin/bundle exec rubocop
publish: image
@echo Publishing image: ${REPO}:${TAG} ...
@docker tag ${NAME}:${TAG} ${REPO}:${TAG} 2>&1
@docker push ${REPO}:${TAG} 2>&1
@echo Done.
realclean: clean
@rm -f ${GITHUB_TOKEN} ${BUNDLE_CFG}
run: start
@if docker network inspect dnet > /dev/null 2>&1; then echo "Using docker network dnet"; else echo "Create docker network dnet"; docker network create dnet; sleep 2; fi
@docker run -p ${PORT}:3000 -e API_SERVICE_URL=${API_SERVICE_URL} --network dnet --rm --name ${SHORTNAME} ${NAME}:${TAG}
secret:
@echo "Creating secret ..."
@export SECRET_KEY_BASE=$(./bin/rails secret)
server:
@echo "Starting local server ..."
@API_SERVICE_URL=${API_SERVICE_URL} ./bin/rails server -p ${PORT}
start:
@docker stop ${SHORTNAME} > /dev/null 2>&1 || :
@echo "Starting ${SHORTNAME} ..."
tag:
@echo ${TAG}
test: assets
@echo "Running unit tests ..."
@./bin/rails test
vars:
@echo "Docker: ${REPO}:${TAG}"
@echo "ACCOUNT = ${ACCOUNT}"
@echo "ALPINE_VERSION = ${ALPINE_VERSION}"
@echo "AWS_REGION = ${AWS_REGION}"
@echo "BUNDLER_VERSION = ${BUNDLER_VERSION}"
@echo "ECR = ${ECR}"
@echo "GPR_OWNER = ${GPR_OWNER}"
@echo "NAME = ${NAME}"
@echo "RUBY_VERSION = ${RUBY_VERSION}"
@echo "SHORTNAME = ${SHORTNAME}"
@echo "STAGE = ${STAGE}"
@echo "COMMIT = ${COMMIT}"
@echo "REPO = ${REPO}"
@echo "TAG = ${TAG}"
@echo "VERSION = ${VERSION}"