Skip to content

Commit

Permalink
Remove code for GCP Project
Browse files Browse the repository at this point in the history
  • Loading branch information
umatare5 committed Apr 30, 2022
1 parent da4ac10 commit 2564c43
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 99 deletions.
9 changes: 0 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,3 @@ test:
.PHONY: start
start:
./scripts/deploy.sh

.PHONY: deploy
deploy:
./scripts/deploy.sh gcp

.PHONY: release
release:
git bump
goreleaser release --rm-dist
13 changes: 0 additions & 13 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Prepare variables
ENV=$1
APP_NAME=logbook-api
GCP_PROJECT=$GCP_PROJECT
LOCAL_BUILD_DIR=.

# Load libraries
Expand All @@ -17,18 +16,6 @@ validate_current_dir $APP_NAME
validate_curl_exists
validate_docker_exists

# Build container and start it on GCP
if [ "${ENV}" = "gcp" ]; then
validate_gcloud_exists
validate_gcloud_access_token_exists
validate_gcloud_project_configured ${GCP_PROJECT}

if build_on_gcp $APP_NAME $LOCAL_BUILD_DIR $GCP_PROJECT; then
deploy_to_gcp $APP_NAME $LOCAL_BUILD_DIR $GCP_PROJECT
fi
exit
fi

# Build container and start it on Docker Engine
if build_on_local $APP_NAME $LOCAL_BUILD_DIR; then
deploy_to_local $APP_NAME $LOCAL_BUILD_DIR
Expand Down
14 changes: 0 additions & 14 deletions scripts/lib/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,3 @@ function build_on_local() {
# Build new image
docker build -t "${APP_NAME}:${CONTAINER_IMAGE_TAG}" "${LOCAL_BUILD_DIR}"
}

# Build and upload new image into Cloud Build Registry on GCP
function build_on_gcp() {
local APP_NAME=$1
local LOCAL_BUILD_DIR=$2
local GCP_PROJECT=$3
local GCR_LOCATION=asia.gcr.io
local CONTAINER_IMAGE_TAG=latest

# Build and push new image
gcloud builds submit ${LOCAL_BUILD_DIR} \
--tag ${GCR_LOCATION}/${GCP_PROJECT}/${APP_NAME}:${CONTAINER_IMAGE_TAG} \
--project ${GCP_PROJECT}
}
23 changes: 0 additions & 23 deletions scripts/lib/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
# Build a container from local image to boot on Cloud Run
function deploy_to_gcp() {
local APP_NAME=$1
local LOCAL_BUILD_DIR=$2
local GCP_PROJECT=$3
local GCR_LOCATION=asia.gcr.io
local GCR_REGION=asia-northeast1
local CONTAINER_IMAGE_TAG=latest

# Build and run a container from image
gcloud run deploy ${APP_NAME} \
--image ${GCR_LOCATION}/${GCP_PROJECT}/${APP_NAME}:${CONTAINER_IMAGE_TAG} \
--project ${GCP_PROJECT} \
--region ${GCR_REGION} \
--update-env-vars \
LOGBOOK_ATMOS_API=$LOGBOOK_ATMOS_API,LOGBOOK_ATMOS_TOKEN=$LOGBOOK_ATMOS_TOKEN \
--no-traffic \
--allow-unauthenticated

# Show more help
show_gcloud_run_help ${APP_NAME} ${GCR_REGION}
}

# Build a container from local image to boot on local
function deploy_to_local() {
local APP_NAME=$1
Expand Down
19 changes: 0 additions & 19 deletions scripts/lib/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,3 @@ function show_docker_container_help() {
echo -e "docker container exec -it ${DOCKER_CONTAINER_ID} /bin/sh"
echo
}

# Guide gcloud run commands
function show_gcloud_run_help() {
local APP_NAME=$1
local GCR_REGION=$2

echo -e "\nNext Step:"
echo -e "\n* Describe the detail about a service"
echo -e "gcloud run services describe ${APP_NAME} --region ${GCR_REGION}"
echo -e "\n* List available revisions for a service"
echo -e "gcloud run revisions list --service ${APP_NAME} --region ${GCR_REGION}"
echo -e "\n* Assign 100% of traffic to the latest revision <<CAUTION: UPDATES WILL BE APPLIED TO CLIENTS!>>"
echo -e "gcloud run services update-traffic ${APP_NAME} --region ${GCR_REGION} --to-latest"
echo -e "\n* Describe the detail about a revision (Note: {REVISION_NANE} can be get by 'gcloud run revisions list')"
echo -e "gcloud run revisions describe --region ${GCR_REGION} {REVISION_NAME}"
echo -e "\n* Rollback to a revision (Note: {REVISION_NANE} can be get by 'gcloud run revisions list')"
echo -e "gcloud run services update-traffic ${APP_NAME} --region ${GCR_REGION} --to-revisions {REVISION_NAME}=100"
echo
}
21 changes: 0 additions & 21 deletions scripts/lib/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,3 @@ function validate_docker_exists(){
exit 1
fi
}

# Check gcloud exists
function validate_gcloud_exists(){
if ! gcloud --version > /dev/null ; then
exit 1
fi
}

# Check access token exists
function validate_gcloud_access_token_exists(){
if ! gcloud auth print-access-token > /dev/null ; then
exit 1
fi
}

# Check gcloud project configured
function validate_gcloud_project_configured(){
if ! gcloud config configurations activate ${GCP_PROJECT} > /dev/null ; then
exit 1
fi
}

0 comments on commit 2564c43

Please sign in to comment.