Skip to content
Snippets Groups Projects
Commit c013cc1d authored by Will McCutchen's avatar Will McCutchen
Browse files

Deploy to fly.io

parent 52382e08
No related branches found
No related tags found
No related merge requests found
name: Cleanup
on:
pull_request:
branches: [master]
types: [closed]
jobs:
cleanup_staging_deploy:
name: Cleanup Staging Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup gcloud CLI
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '285.0.0'
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
- name: Setup deployment parameters
id: deployment_params
run: |
pr_number=$(jq -r .pull_request.number "$GITHUB_EVENT_PATH")
echo "::set-output name=version::pr${pr_number}"
- name: Remove deployment
run: gcloud app versions delete --project="${{ secrets.GCP_PROJECT_ID }}" "${{ steps.deployment_params.outputs.version }}"
# This workflow implements continuous delivery with automated testing and fully
# autonomous deploys to staging and production.
#
# If executed on a pull request, this will trigger a "staging" deploy to a
# non-primary app engine version named "pr<number>" for the current pull
# request number IFF tests pass.
#
# If executed on a push to master, this will trigger a "production" deploy IFF
# tests pass.
#
# A separate "Cleanup" workflow (cleanup.yaml) runs when pull requests are
# closed to remove the staging deploy for that pull request.
# autonomous deploys to production on merge.
name: CD
# Translated: "Execute this workflow on pushes to master OR on pull requests
......@@ -24,19 +14,6 @@ on:
branches: [master]
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Setup
uses: actions/setup-go@v2
- name: Checkout
uses: actions/checkout@v2
- name: Lint
run: make lint
test:
name: Test
runs-on: ubuntu-latest
......@@ -50,8 +27,11 @@ jobs:
- name: Build
run: make build
- name: Lint
run: make lint
- name: Test
run: make testci
run: git show && make testci
- name: Code coverage
uses: codecov/codecov-action@v1
......@@ -81,95 +61,36 @@ jobs:
- name: Test
run: make test
staging_deploy:
name: Staging Deploy
if: github.ref != 'refs/heads/master'
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup gcloud CLI
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '285.0.0'
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
- name: Setup deployment parameters
id: deployment_params
run: |
pr_number=$(jq -r .pull_request.number "$GITHUB_EVENT_PATH")
echo "::set-output name=version::pr${pr_number}"
- name: Notify start
id: deployment
uses: bobheadxi/deployments@v0.4.0
with:
env: staging
ref: ${{ github.head_ref }}
step: start
token: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy
run: gcloud app deploy --quiet --no-promote --project="${{ secrets.GCP_PROJECT_ID }}" --version="${{ steps.deployment_params.outputs.version }}"
- name: Notify finish
uses: bobheadxi/deployments@v0.4.0
with:
step: finish
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
token: ${{ secrets.GITHUB_TOKEN }}
env: staging
status: ${{ job.status }}
env_url: 'https://${{ steps.deployment_params.outputs.version }}-dot-httpbingo.uc.r.appspot.com'
logs: 'https://console.cloud.google.com/logs/viewer?project=${{ secrets.GCP_PROJECT_ID }}&resource=gae_app%2Fmodule_id%2Fdefault%2Fversion_id%2F${{ steps.deployment_params.outputs.version }}'
production_deploy:
name: Production Deploy
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
needs: [lint, test]
needs: [test]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup gcloud CLI
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '285.0.0'
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
- name: Setup deployment parameters
id: deployment_params
run: |
version=$(echo "${GITHUB_SHA}" | head -c 8)
echo "::set-output name=version::${version}"
- name: Notify start
id: deployment
uses: bobheadxi/deployments@v0.4.0
uses: bobheadxi/deployments@v0.4.2
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: staging
env: production
- name: Deploy
run: gcloud app deploy --quiet --project="${{ secrets.GCP_PROJECT_ID }}" --version="${{ steps.deployment_params.outputs.version }}"
uses: superfly/flyctl-actions@1.1
with:
args: "deploy --strategy rolling"
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- name: Notify finish
uses: bobheadxi/deployments@v0.4.0
uses: bobheadxi/deployments@v0.4.2
with:
step: finish
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
token: ${{ secrets.GITHUB_TOKEN }}
env: staging
env: production
status: ${{ job.status }}
env_url: 'https://${{ steps.deployment_params.outputs.version }}-dot-httpbingo.uc.r.appspot.com'
logs: 'https://console.cloud.google.com/logs/viewer?project=${{ secrets.GCP_PROJECT_ID }}&resource=gae_app%2Fmodule_id%2Fdefault%2Fversion_id%2F${{ steps.deployment_params.outputs.version }}'
env_url: 'https://httpbingo.org'
......@@ -95,11 +95,21 @@ lint: $(TOOL_GOLINT) $(TOOL_STATICCHECK)
run: build
$(DIST_PATH)/go-httpbin
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: gcloud-auth imagepush
deploy-cloud-run: gcloud-auth imagepush
$(GCLOUD_COMMAND) beta run deploy \
$(GCLOUD_PROJECT) \
--image=$(DOCKER_TAG_GCLOUD) \
......@@ -109,8 +119,9 @@ deploy: gcloud-auth imagepush
--region=$(GCLOUD_REGION) \
--allow-unauthenticated \
--platform=managed
$(GCLOUD_COMMAND) run services update-traffic --to-latest
stagedeploy: gcloud-auth imagepush
stagedeploy-cloud-run: gcloud-auth imagepush
$(GCLOUD_COMMAND) beta run deploy \
$(GCLOUD_PROJECT) \
--image=$(DOCKER_TAG_GCLOUD) \
......@@ -126,9 +137,6 @@ 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
watch: $(TOOL_REFLEX)
reflex -s -r '\.(go|html)$$' make run
# =============================================================================
# docker images
......
fly.toml 0 → 100644
app = "httpbingo"
[[services]]
internal_port = 8080
protocol = "tcp"
[services.concurrency]
hard_limit = 25
soft_limit = 20
[[services.ports]]
handlers = ["http"]
port = "80"
[[services.ports]]
handlers = ["tls", "http"]
port = "443"
[[services.tcp_checks]]
interval = 10000
timeout = 2000
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment