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

Deploy to fly.io

parent 52382e08
Branches
Tags
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 # This workflow implements continuous delivery with automated testing and fully
# autonomous deploys to staging and production. # autonomous deploys to production on merge.
#
# 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.
name: CD name: CD
# Translated: "Execute this workflow on pushes to master OR on pull requests # Translated: "Execute this workflow on pushes to master OR on pull requests
...@@ -24,19 +14,6 @@ on: ...@@ -24,19 +14,6 @@ on:
branches: [master] branches: [master]
jobs: 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: test:
name: Test name: Test
runs-on: ubuntu-latest runs-on: ubuntu-latest
...@@ -50,8 +27,11 @@ jobs: ...@@ -50,8 +27,11 @@ jobs:
- name: Build - name: Build
run: make build run: make build
- name: Lint
run: make lint
- name: Test - name: Test
run: make testci run: git show && make testci
- name: Code coverage - name: Code coverage
uses: codecov/codecov-action@v1 uses: codecov/codecov-action@v1
...@@ -81,95 +61,36 @@ jobs: ...@@ -81,95 +61,36 @@ jobs:
- name: Test - name: Test
run: make 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: production_deploy:
name: Production Deploy name: Production Deploy
if: github.ref == 'refs/heads/master' if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [lint, test] needs: [test]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 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 - name: Notify start
id: deployment id: deployment
uses: bobheadxi/deployments@v0.4.0 uses: bobheadxi/deployments@v0.4.2
with: with:
step: start step: start
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
env: staging env: production
- name: Deploy - 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 - name: Notify finish
uses: bobheadxi/deployments@v0.4.0 uses: bobheadxi/deployments@v0.4.2
with: with:
step: finish step: finish
deployment_id: ${{ steps.deployment.outputs.deployment_id }} deployment_id: ${{ steps.deployment.outputs.deployment_id }}
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
env: staging env: production
status: ${{ job.status }} status: ${{ job.status }}
env_url: 'https://${{ steps.deployment_params.outputs.version }}-dot-httpbingo.uc.r.appspot.com' env_url: 'https://httpbingo.org'
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 }}'
...@@ -95,11 +95,21 @@ lint: $(TOOL_GOLINT) $(TOOL_STATICCHECK) ...@@ -95,11 +95,21 @@ lint: $(TOOL_GOLINT) $(TOOL_STATICCHECK)
run: build run: build
$(DIST_PATH)/go-httpbin $(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 to google cloud run
# ============================================================================= # =============================================================================
deploy: gcloud-auth imagepush deploy-cloud-run: gcloud-auth imagepush
$(GCLOUD_COMMAND) beta run deploy \ $(GCLOUD_COMMAND) beta run deploy \
$(GCLOUD_PROJECT) \ $(GCLOUD_PROJECT) \
--image=$(DOCKER_TAG_GCLOUD) \ --image=$(DOCKER_TAG_GCLOUD) \
...@@ -109,8 +119,9 @@ deploy: gcloud-auth imagepush ...@@ -109,8 +119,9 @@ deploy: gcloud-auth imagepush
--region=$(GCLOUD_REGION) \ --region=$(GCLOUD_REGION) \
--allow-unauthenticated \ --allow-unauthenticated \
--platform=managed --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_COMMAND) beta run deploy \
$(GCLOUD_PROJECT) \ $(GCLOUD_PROJECT) \
--image=$(DOCKER_TAG_GCLOUD) \ --image=$(DOCKER_TAG_GCLOUD) \
...@@ -126,9 +137,6 @@ gcloud-auth: ...@@ -126,9 +137,6 @@ gcloud-auth:
@$(GCLOUD_COMMAND) auth list | grep '^\*' | grep -q $(GCLOUD_ACCOUNT) || $(GCLOUD_COMMAND) auth login $(GCLOUD_ACCOUNT) @$(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 @$(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 # 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