Skip to content

Commit

Permalink
Refactor Makefile aws-vault related rules (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
pziemkowski authored Jul 20, 2020
1 parent 71deeed commit ff2ed28
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 28 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ install: install-infra-cdk install-infra-functions

setup-infra:
chmod +x ./scripts/*.sh
$(AWS_VAULT) scripts/cdk-bootstrap.sh
scripts/cdk-bootstrap.sh

setup-docker:
docker volume create --name=$(PROJECT_NAME)-web-backend-db-data
Expand Down Expand Up @@ -48,7 +48,7 @@ deploy-infra-functions:
deploy-stage-infra: deploy-infra-main deploy-infra-functions deploy-infra-ci

upload-version:
$(AWS_VAULT) node $(BASE_DIR)/scripts/upload-version.js api,workers,webapp,admin-panel
node $(BASE_DIR)/scripts/upload-version.js api,workers,webapp,admin-panel


#
Expand All @@ -57,7 +57,7 @@ upload-version:

build:
@echo Build version: $(VERSION)
$(AWS_VAULT) $(MAKE) -C services/backend build
$(MAKE) -C services/backend build
$(MAKE) -C services/webapp build
$(MAKE) -C services/workers build

Expand Down
14 changes: 5 additions & 9 deletions base.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@ export API_DOMAIN := $(call GetFromEnvCfg,domains.api)
export WEB_APP_DOMAIN := $(call GetFromEnvCfg,domains.webApp)
export WWW_DOMAIN := $(call GetFromEnvCfg,domains.www)

AWS_VAULT_PROFILE ?= $(call GetFromCfg,aws.profile)
AWS_VAULT = aws-vault exec $(AWS_VAULT_PROFILE) --

ifeq ($(CI),true)
AWS_VAULT =
VERSION := $(shell cat $(BASE_DIR)/VERSION)
DOCKER_COMPOSE = docker-compose -p $(PROJECT_NAME)_$(HOST_UID) -f $(BASE_DIR)/docker-compose.yml -f $(BASE_DIR)/docker-compose.ci.yml
else ifeq ($(ENV_STAGE),local)
AWS_VAULT =
VERSION := $(shell git describe --tags --first-parent --abbrev=11 --long --dirty --always)
DOCKER_COMPOSE = docker-compose -p $(PROJECT_NAME)_$(HOST_UID)
else
AWS_VAULT_PROFILE := $(call GetFromCfg,aws.profile)
AWS_VAULT = aws-vault exec $(AWS_VAULT_PROFILE) --
VERSION := $(shell git describe --tags --first-parent --abbrev=11 --long --dirty --always)
DOCKER_COMPOSE = docker-compose -p $(PROJECT_NAME)_$(HOST_UID)
endif
Expand Down Expand Up @@ -86,7 +82,7 @@ install-scripts:
shell:
$(USER_SHELL)

aws-shell:
aws-vault:
$(AWS_VAULT) $(USER_SHELL)

up:
Expand All @@ -107,4 +103,4 @@ prune:
docker system prune -af

upload-service-version:
$(AWS_VAULT) node $(BASE_DIR)/scripts/upload-service-version.js $(SERVICE_NAME)
node $(BASE_DIR)/scripts/upload-service-version.js $(SERVICE_NAME)
5 changes: 5 additions & 0 deletions docs/app-deployment.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Deploy the app to AWS

## Switch to AWS context using aws-vault
```shell script
make aws-vault
```

## Deploy infrastructure of the environment

```shell script
Expand Down
5 changes: 5 additions & 0 deletions docs/create-new-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ This command will create following file named `.awsboilerplate.<ENV_STAGE_NAME>.

## Deploy infrastructure of the new environment

### Switch to AWS context using aws-vault
```shell script
make aws-vault
```

```shell script
make deploy-stage-infra ENV_STAGE=<ENV_STAGE_NAME>
```
Expand Down
6 changes: 6 additions & 0 deletions docs/global-infra-deployment.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Deploy Global Infrastructure to AWS
This command will deploy [Global infrastructure](/docs/infrastructure-components.md#global-infrastructure) CDK stack

## Switch to AWS context using aws-vault
```shell script
make aws-vault
```

## Deploy CDK Stack
```shell script
make deploy-global-infra
```
2 changes: 1 addition & 1 deletion docs/services/create-new-serverless-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ build:
@echo "Test <CHANGE_ME>"

deploy:
$(AWS_VAULT) sls deploy --stage $(ENV_STAGE);
sls deploy --stage $(ENV_STAGE);
$(MAKE) upload-service-version SERVICE_NAME=<CHANGE_ME>;
```

Expand Down
6 changes: 5 additions & 1 deletion docs/setup-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ sh ./setup.sh

This script will install all possible package dependencies.

#### Run CDK bootstrap [^1]
#### Switch to AWS context using aws-vault [^1]
```shell script
make aws-vault
```

#### Run CDK bootstrap [^1]
```shell script
make setup-infra
```
Expand Down
18 changes: 9 additions & 9 deletions infra/cdk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@ install:

deploy-global-infra:
npm run build;
$(AWS_VAULT) npm run cdk deploy *GlobalStack;
npm run cdk deploy *GlobalStack;

deploy-global-tools:
$(MAKE) -C $(BASE_DIR)/tools/version-matrix install
$(MAKE) -C $(BASE_DIR)/tools/version-matrix build

npm run build;
$(AWS_VAULT) npm run cdk deploy *GlobalToolsStack;
npm run cdk deploy *GlobalToolsStack;

deploy-infra-main:
npm run build;
$(AWS_VAULT) npm run cdk deploy *MainStack;
npm run cdk deploy *MainStack;

deploy-infra-ci:
pwd;
npm run build;
$(AWS_VAULT) npm run cdk deploy *CiStack;
npm run cdk deploy *CiStack;

deploy-components:
npm run build;
$(AWS_VAULT) npm run cdk deploy *ComponentsStack;
npm run cdk deploy *ComponentsStack;

deploy-admin-panel:
npm run build;
$(AWS_VAULT) npm run cdk deploy *AdminPanelStack;
npm run cdk deploy *AdminPanelStack;

deploy-api:
npm run build;
$(AWS_VAULT) npm run cdk deploy *ApiStack;
npm run cdk deploy *ApiStack;

deploy-migrations:
npm run build;
$(AWS_VAULT) npm run cdk deploy *MigrationsStack;
npm run cdk deploy *MigrationsStack;

deploy-webapp:
npm run build;
$(AWS_VAULT) npm run cdk deploy *WebAppStack;
npm run cdk deploy *WebAppStack;
2 changes: 1 addition & 1 deletion infra/functions/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ install:
npm install

deploy:
$(AWS_VAULT) $(SELF_DIR)node_modules/.bin/sls deploy --stage $(ENV_STAGE);
$(SELF_DIR)node_modules/.bin/sls deploy --stage $(ENV_STAGE);
4 changes: 2 additions & 2 deletions services/backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test:

build:
$(MAKE) test
$(AWS_VAULT) /bin/sh ./scripts/build.sh
/bin/sh ./scripts/build.sh

deploy-admin-panel:
$(MAKE) -C $(BASE_DIR)/infra/cdk deploy-admin-panel
Expand All @@ -28,7 +28,7 @@ deploy-migrations:
$(MAKE) -C $(BASE_DIR)/infra/cdk deploy-migrations

cd $(BASE_DIR)/infra/functions;\
$(AWS_VAULT) node_modules/.bin/sls invoke --stage $(ENV_STAGE) -f TriggerMigrationsJob
node_modules/.bin/sls invoke --stage $(ENV_STAGE) -f TriggerMigrationsJob

deploy: deploy-migrations deploy-admin-panel deploy-api

Expand Down
4 changes: 2 additions & 2 deletions services/workers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test:
build: test

deploy:
$(AWS_VAULT) $(SELF_DIR)node_modules/.bin/sls deploy --stage $(ENV_STAGE);
$(SELF_DIR)node_modules/.bin/sls deploy --stage $(ENV_STAGE);
$(MAKE) upload-service-version SERVICE_NAME=workers

flake8:
Expand All @@ -34,5 +34,5 @@ black:
pipenv run black --config=pyproject.toml .

invoke-hello:
$(AWS_VAULT) sls invoke --stage $(ENV_STAGE) -f hello;
sls invoke --stage $(ENV_STAGE) -f hello;

0 comments on commit ff2ed28

Please sign in to comment.