Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Deploy for Multiple Channels #376

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions .github/workflows/deploy-prod-env.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/deploy-test-env.yml

This file was deleted.

92 changes: 92 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Deploy branches to channels

on:
push:
branches: '**'

env:
node_version: '18.x'
project-directory: ./

jobs:
deploy:
name: Deploy branch to channel
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.branch-names.outputs.current_branch }}
channel: ${{ steps.get-channel.outputs.channel }}
DIGITALOCEAN_TOKEN: ${{ steps.resolver.outputs.DIGITALOCEAN_TOKEN }}
CLUSTER_NAME: ${{ steps.resolver.outputs.CLUSTER_NAME }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Get branch names
id: branch-names
uses: tj-actions/branch-names@v8

- name: Get npm version
id: package-version
uses: martinbeentjes/npm-get-version-action@master

- name: Get channel information
id: get-channel
run: |
BRANCH_NAME="${{ steps.branch-names.outputs.current_branch }}"
content=$(<.releaserc)
branches=$(jq -r '.branches | keys[]' <<< "$content")
for branch in $branches; do
branch_name=$(jq -r ".branches[$branch].name" <<< "$content")
if [[ "$BRANCH_NAME" =~ $branch_name ]]; then
channel=$(jq -r ".branches[$branch].channel" <<< "$content")
echo "::set-output name=channel::$channel"
exit 0
fi
done
echo "No channel found for branch $BRANCH_NAME"
exit 1
shell: bash

- name: Get deploy token
id: resolver
run: |
CHANNEL="${{ steps.get-channel.outputs.channel }}"
case "$CHANNEL" in
"rc")
echo "::set-output name=DIGITALOCEAN_TOKEN::${{ secrets.DIGITALOCEAN_PRODUCTION_TOKEN }}"
echo "::set-output name=CLUSTER_NAME::${{ secrets.PRODUCTION_CLUSTER_NAME }}"
;;
"alpha")
echo "::set-output name=DIGITALOCEAN_TOKEN::${{ secrets.TEST_DIGITALOCEAN_TOKEN }}"
echo "::set-output name=CLUSTER_NAME::${{ secrets.TEST_CLUSTER_NAME }}"
;;
*)
echo "No token found for channel $CHANNEL"
exit 1
;;
esac
shell: bash

- name: Deploy to channel
id: deploy
run: |
echo "Branch: ${{ steps.branch-names.outputs.current_branch }}"
echo "Channel: ${{ steps.get-channel.outputs.channel }}"
echo "DIGITALOCEAN_TOKEN: ${{ steps.resolver.outputs.DIGITALOCEAN_TOKEN }}"
echo "CLUSTER_NAME: ${{ steps.resolver.outputs.CLUSTER_NAME }}"

- name: Run kustomize
run: (cd ./deployment/base && ../../kustomize edit set image greenstand/treetracker-query-api:${{ steps.package-version.outputs.current-version }} )
working-directory: ${{ env.project-directory }}

- name: Install doctl for kubernetes
uses: digitalocean/action-doctl@v2
with:
token: ${{ steps.resolver.outputs.DIGITALOCEAN_TOKEN }}

- name: Save DigitalOcean kubeconfig
run: doctl kubernetes cluster kubeconfig save ${{ steps.resolver.outputs.CLUSTER_NAME }}

- name: Update kubernetes resources
run: kustomize build deployment/overlays/prod | kubectl apply -n webmap --wait -f -
working-directory: ${{ env.project-directory }}
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
npx lint-staged
19 changes: 18 additions & 1 deletion .releaserc
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
{
"branches": ["main"],
"branches": [
{
"name":"main",
"channel": "rc"
},
{
"name":"alpha/*",
"channel": "alpha"
},
{
"name":"beta/*",
"channel": "beta"
},
{
"name":"rc/*",
"channel": "rc"
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading