Skip to content

Commit

Permalink
Separate staging and prod
Browse files Browse the repository at this point in the history
  • Loading branch information
sidpalas committed Oct 2, 2020
1 parent 8282500 commit e041bcb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/build-push-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- master
tags:
- v\d+.\d+.\d+

env:
PROJECT_ID: devops-directive-traversy
Expand All @@ -14,6 +16,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Set ENV
run: |-
if [ ${GITHUB_REF##*/} = "master" ]; then
echo "::set-env name=ENV::staging"
else
echo "::set-env name=ENV::prod"
fi
- name: Checkout
uses: actions/checkout@v2

Expand Down
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@ create-tf-backend-bucket:

###

check-env:
ifndef ENV
$(error Please set ENV=[staging|prod])
endif

define get-secret
$(shell gcloud secrets versions access latest --secret=$(1) --project=$(PROJECT_ID))
endef

###

ENV=staging

terraform-create-workspace:
terraform-create-workspace: check-env
cd terraform && \
terraform workspace new $(ENV)

terraform-init:
terraform-init: check-env
cd terraform && \
terraform workspace select $(ENV) && \
terraform init

TF_ACTION?=plan
terraform-action:
terraform-action: check-env
@cd terraform && \
terraform workspace select $(ENV) && \
terraform $(TF_ACTION) \
Expand All @@ -50,12 +53,12 @@ REMOTE_TAG=gcr.io/$(PROJECT_ID)/$(LOCAL_TAG)
CONTAINER_NAME=storybooks-api
DB_NAME=storybooks

ssh:
ssh: check-env
gcloud compute ssh $(SSH_STRING) \
--project=$(PROJECT_ID) \
--zone=$(ZONE)

ssh-cmd:
ssh-cmd: check-env
@gcloud compute ssh $(SSH_STRING) \
--project=$(PROJECT_ID) \
--zone=$(ZONE) \
Expand All @@ -68,7 +71,7 @@ push:
docker tag $(LOCAL_TAG) $(REMOTE_TAG)
docker push $(REMOTE_TAG)

deploy:
deploy: check-env
$(MAKE) ssh-cmd CMD='docker-credential-gcr configure-docker'
@echo "pulling new container image..."
$(MAKE) ssh-cmd CMD='docker pull $(REMOTE_TAG)'
Expand Down
1 change: 1 addition & 0 deletions terraform/environments/prod/config.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gcp_machine_type = "n1-standard-4"
2 changes: 1 addition & 1 deletion views/partials/_header.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav class="grey darken-3">
<div class="nav-wrapper container">

<a href="#!" class="brand-logo center">StoryBooks</a>
<a href="#!" class="brand-logo center">StoryBooks!!!</a>
<a href="#" data-target="mobile-demo" class="sidenav-trigger show-on-large"><i class="fas fa-bars"></i></a>
<ul class="sidenav" id="mobile-demo">
<li><a href="/stories">Public Stories</a></li>
Expand Down

0 comments on commit e041bcb

Please sign in to comment.