diff --git a/.github/workflows/production-deploy.yml b/.github/workflows/production-deploy.yml index 5334456..53b8813 100644 --- a/.github/workflows/production-deploy.yml +++ b/.github/workflows/production-deploy.yml @@ -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/ssh-action@v1.0.0 + 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 diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml deleted file mode 100644 index 2a7f429..0000000 --- a/.github/workflows/staging-deploy.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: build - -on: - push: - branches: - - master - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - staging-deployment: - 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/ diff --git a/Dockerfile b/Dockerfile index fc87af7..a850658 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM golang:1.20 +RUN apt update && apt install -y python3-pip + WORKDIR /srv/root COPY go.mod go.sum ./ diff --git a/Makefile b/Makefile index fa2219e..9e53b37 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/scripts/start.sh b/scripts/start.sh index b791ead..d4afa2a 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -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 @@ -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