Skip to content

Commit

Permalink
fix: update github workflow and kubernetes deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Kpoke committed Jul 18, 2022
1 parent f975dc7 commit 54eb729
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 343 deletions.
116 changes: 0 additions & 116 deletions .github/workflows/treetracker-wallet-api-build-deploy-dev.outdate

This file was deleted.

185 changes: 86 additions & 99 deletions .github/workflows/treetracker-wallet-api-build-deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -1,126 +1,113 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Deploy to Dev Env
name: Deploy to Dev Env

on:
push:
branches:
- master

env:
env:
project-directory: ./

jobs:
build:
name: Release and Build
release:
name: Release
runs-on: ubuntu-latest
if: |
!contains(github.event.head_commit.message, 'skip-ci') &&
github.event_name == 'push' &&
github.repository == 'Greenstand/treetracker-wallet-api'
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm i -g semantic-release @semantic-release/{git,exec,changelog}
- run: semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: npm clean install
run: npm ci
working-directory: ${{ env.project-directory }}
- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@master
with:
path: ./
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build snapshot with git sha and push on merge
id: docker_build_snapshot_merge
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
push: true
tags: greenstand/treetracker-wallet-api:${{ steps.package-version.outputs.current-version }}
- shell: bash
run: |
echo '${{ steps.package-version.outputs.current-version }}' > image-tag
- name: persist tag name
uses: actions/upload-artifact@v1
with:
name: image-tag-${{github.sha}}
path: image-tag


deploy:
name: Deploy latest to development environment
runs-on: ubuntu-latest
needs: build
if: |
!contains(github.event.head_commit.message, 'skip-ci') &&
github.event_name == 'push' &&
github.repository == 'Greenstand/${{ github.event.repository.name }}'
steps:
- uses: actions/checkout@v2
- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@master
with:
path: ./
- name: Download tag name
uses: actions/download-artifact@v1
with:
name: image-tag-${{github.sha}}
- name: Set image tag name
id: image-tag-name
run: |
value=`cat image-tag-${{github.sha}}/image-tag`
echo "::set-output name=image-tag-name::$value"
- name: Install kustomize
run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
- name: Run kustomize
run: (cd deployment/base && ../../kustomize edit set image greenstand/treetracker-wallet-api:${{ steps.image-tag-name.outputs.image-tag-name }} )
- name: Install doctl for kubernetes
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DEV_DIGITALOCEAN_TOKEN }}
- name: Save DigitalOcean kubeconfig
run: doctl kubernetes cluster kubeconfig save ${{ secrets.DEV_CLUSTER_NAME}}
- name: Delete completed migration jobs prior to deployment
run: kubectl -n wallet-api delete job --ignore-not-found=true wallet-db-migration-job
- name: Update kubernetes resources
run: kustomize build deployment/overlays/development | kubectl apply -n ${{ secrets.K8S_NAMESPACE }} --wait -f -
# - name: Attempt to wait for migration job to complete
# run: kubectl wait --for=condition=complete --timeout=45s job/wallet-db-migration-job
- uses: actions/checkout@v2

- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: '16.x'

- name: npm clean install
run: npm ci
working-directory: ${{ env.project-directory }}

- run: npm i -g semantic-release @semantic-release/{git,exec,changelog}

- run: semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build snapshot and push on merge
id: docker_build_release
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
push: true
tags: greenstand/treetracker-wallet-api:${{ steps.package-version.outputs.current-version }}

- id: export_bumped_version
run: |
export BUMPED_VERSION="${{ steps.package-version.outputs.current-version }}"
echo "::set-output name=bumped_version::${BUMPED_VERSION}"
- name: Install kustomize
run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash

- name: Run kustomize
run: (cd deployment/overlays/development && ../../../kustomize edit set image greenstand/treetracker-wallet-api:${{ steps.export_bumped_version.outputs.bumped_version }} )

- name: Commit dev kustomization file with new app version
if: |
!contains(github.event.head_commit.message, 'chore')
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -am "chore: bump docker image tag ${{ steps.export_bumped_version.outputs.bumped_version }} [skip ci]"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
outputs:
bumped_version: ${{ steps.export_bumped_version.outputs.bumped_version }}

test:
name: End to End Test
runs-on: ubuntu-latest
needs: deploy
needs: release
env:
ENVIRONMENT: dev

steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12
- name: Install mocha
run: npm install -g mocha
- run: npm ci
- run: echo ${{ secrets.DEVELOPMENT_ENV }}
- run: ${{ secrets.DEVELOPMENT_ENV }} npm run test-e2e
- uses: actions/checkout@v2

- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: '16.x'

- name: Install mocha
run: npm install -g mocha

- run: npm ci

- run: echo ${{ secrets.DEVELOPMENT_ENV }}

- run: ${{ secrets.DEVELOPMENT_ENV }} npm run test-e2e
43 changes: 19 additions & 24 deletions .github/workflows/treetracker-wallet-api-deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@

name: Deploy to Production Env

on:
workflow_dispatch:
inputs:
git-tag:
description: "Branch/hash/tag"
environment:
description: 'git-tag'
required: true
default: 'master'

env:
env:
project-directory: ./

jobs:
deploy-test:
name: Deploy selected tag to production environment, requires approval
deploy-production:
name: Deploy latest to production environment, requires approval
runs-on: ubuntu-latest
if: |
github.repository == 'Greenstand/treetracker-wallet-api'
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.git-tag }}
- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@master
with:
path: ${{ env.project-directory }}

- name: Install kustomize
run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash

- name: Run kustomize
run: (cd deployment/base && ../../kustomize edit set image greenstand/treetracker-wallet-api:${{ steps.package-version.outputs.current-version }} )
- name: Install doctl for kubernetes
uses: digitalocean/action-doctl@v2
run: (cd deployment/overlays/production && ../../../kustomize edit set image greenstand/treetracker-wallet-api:${{ github.event.inputs.environment }})

- name: Commit production kustomization file with new app version
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -am "chore: bump docker image tag ${{ github.event.inputs.environment }} [skip ci]"
- name: Push changes
uses: ad-m/github-push-action@master
with:
token: ${{ secrets.DIGITALOCEAN_PRODUCTION_TOKEN }}
- name: Save DigitalOcean kubeconfig
run: doctl kubernetes cluster kubeconfig save ${{ secrets.PRODUCTION_CLUSTER_NAME }}
- name: Delete completed migration jobs prior to deployment
run: kubectl -n wallet-api delete job --ignore-not-found=true wallet-db-migration-job
- name: Update kubernetes resources
run: kustomize build deployment/overlays/production | kubectl apply -n ${{ secrets.K8S_NAMESPACE }} --wait -f -
github_token: ${{ secrets.GITHUB_TOKEN }}
Loading

0 comments on commit 54eb729

Please sign in to comment.