Skip to content

Commit

Permalink
Merge pull request #31 from osuAkatsuki/AKAT-443-prod-deploys-from-ci
Browse files Browse the repository at this point in the history
Prod deploys from CI
  • Loading branch information
cmyui authored Oct 22, 2023
2 parents 4674ca4 + d4c3dd1 commit d4107aa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 128 deletions.
71 changes: 21 additions & 50 deletions .github/workflows/production-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,26 @@
name: production-deploy

on: workflow_dispatch

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
branches:
- master

jobs:
production-deploy:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Check out latest commit
uses: actions/checkout@v3

- name: Install digitalocean command line interface
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Log-in to digitalocean container registry
run: doctl registry login --expiry-seconds 600

- name: Build container image
run: docker build -t registry.digitalocean.com/akatsuki/akatsuki-api:latest .

- name: Push image to digitalocean container registry
run: docker push registry.digitalocean.com/akatsuki/akatsuki-api:latest

- name: Save kubeconfig from digitalocean
run: doctl k8s cluster kubeconfig save --expiry-seconds 600 akatsuki-staging

- name: Install helm
uses: azure/setup-helm@v3
with:
version: 'latest'
token: ${{ secrets.GITHUB_TOKEN }}
id: install

- name: Install helm-diff
run: helm plugin install https://github.com/databus23/helm-diff

- name: Checkout common-helm-charts repo
uses: actions/checkout@v3
with:
repository: osuAkatsuki/common-helm-charts
token: ${{ secrets.COMMON_HELM_CHARTS_PAT }}
path: common-helm-charts

- name: Show manifest diff since previous release
run: helm diff upgrade --allow-unreleased --values chart/values.yaml akatsuki-api-staging common-helm-charts/microservice-base/

- name: Deploy service to staging cluster
run: helm upgrade --install --atomic --values chart/values.yaml akatsuki-api-staging common-helm-charts/microservice-base/
- name: Run deploy on production
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script_stop: true
script: |
cd /home/akatsuki/akatsuki-api
git pull origin master
docker build -t akatsuki-api:latest .
cd /home/akatsuki/workbench
docker-compose restart \
akatsuki-api
58 changes: 0 additions & 58 deletions .github/workflows/staging-deploy.yml

This file was deleted.

2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM golang:1.20

RUN apt update && apt install -y python3-pip

WORKDIR /srv/root

COPY go.mod go.sum ./
Expand Down
24 changes: 8 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#!/usr/bin/make

build:
docker build -t akatsuki-api:latest -t registry.digitalocean.com/akatsuki/akatsuki-api:latest .

push:
docker push registry.digitalocean.com/akatsuki/akatsuki-api:latest

install:
helm install --values chart/values.yaml akatsuki-api-staging ../common-helm-charts/microservice-base/

uninstall:
helm uninstall akatsuki-api-staging

diff-upgrade:
helm diff upgrade --allow-unreleased --values chart/values.yaml akatsuki-api-staging ../common-helm-charts/microservice-base/

upgrade:
helm upgrade --atomic --values chart/values.yaml akatsuki-api-staging ../common-helm-charts/microservice-base/
docker build -t akatsuki-api:latest .

run-api:
docker run \
--env APP_COMPONENT=api \
--network=host \
--env-file=.env \
-it akatsuki-api:latest
11 changes: 7 additions & 4 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/usr/bin/env bash
set -eo pipefail

if [ -n "$KUBERNETES" ]; then
source /vault/secrets/secrets.txt
fi

if [ -z "$APP_COMPONENT" ]; then
echo "Please set APP_COMPONENT"
exit 1
Expand All @@ -15,6 +11,13 @@ if [ -z "$APP_ENV" ]; then
exit 1
fi

if [[ $PULL_SECRETS_FROM_VAULT -eq 1 ]]; then
# TODO: is there a better way to deal with this?
pip install --break-system-packages -i $PYPI_INDEX_URL akatsuki-cli
akatsuki vault get akatsuki-api $APP_ENV -o .env
source .env
fi

if [ "$APP_COMPONENT" = "api" ]; then
exec ./akatsuki-api
else
Expand Down

0 comments on commit d4107aa

Please sign in to comment.