From 7965da6738058191d7c204685e2c7672f38a208a Mon Sep 17 00:00:00 2001 From: Connor Smith Date: Tue, 29 Oct 2024 02:54:28 +1100 Subject: [PATCH] wip --- .github/workflows/deploy.yml | 109 +++++++++++++++++++++++++++++++ .github/workflows/fly-deploy.yml | 20 +++--- .github/workflows/release.yml | 67 ------------------- Dockerfile | 2 + bash.sh | 3 + fly.toml | 2 + 6 files changed, 126 insertions(+), 77 deletions(-) create mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/release.yml create mode 100644 bash.sh diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..0c07726 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,109 @@ +name: Deploy Junior + +on: + push: + branches: + - main + +concurrency: + group: deploy-group + +jobs: + build-release: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - name: Get version + id: version + run: | + version=$(git describe --tags --abbrev=0) + next_version=$(($version + 1)) + echo "version=$next_version" >> $GITHUB_OUTPUT + + - name: Collect Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/twohoursonelife/junior + tags: | + type=raw,value=${{ steps.version.outputs.version }} + type=sha + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ github.token }} + + # TODO: Reconsider building this into the image itself since restructure + - name: Add version.txt + run: echo ${{ steps.version.outputs.version }} > version.txt + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . # Intentionally using Path context to include version.txt + push: true + tags: ${{ steps.meta.outputs.tags }}, ghcr.io/twohoursonelife/junior:latest + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Create release + uses: ncipollo/release-action@v1 + with: + generateReleaseNotes: true + makeLatest: true + tag: ${{ steps.version.outputs.version }} + + deploy-commands: + runs-on: ubuntu-latest + environment: prod-commands + steps: + - uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "20" + + - name: Install dependencies + run: npm ci + + - name: Deploy commands + run: node deploy-commands.js + env: + PROD_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }} + + deploy: + runs-on: ubuntu-latest + needs: + - build-release + environment: prod + steps: + - uses: actions/checkout@v4 + + # Deploy commands + - uses: oven-sh/setup-bun@v2 + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Deploy commands + run: bun run deploy-commands.js + env: + PROD_TOKEN: ${{ secrets.BOT_TOKEN }} + + # Deploy to Fly + - uses: superfly/flyctl-actions/setup-flyctl@master + + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml index 26e741d..7b0881a 100644 --- a/.github/workflows/fly-deploy.yml +++ b/.github/workflows/fly-deploy.yml @@ -6,13 +6,13 @@ # branches: # - main # jobs: -# deploy: -# name: Deploy app -# runs-on: ubuntu-latest -# concurrency: deploy-group # optional: ensure only one action runs at a time -# steps: -# - uses: actions/checkout@v4 -# - uses: superfly/flyctl-actions/setup-flyctl@master -# - run: flyctl deploy --remote-only -# env: -# FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} + deploy: + name: Deploy app + runs-on: ubuntu-latest + concurrency: deploy-group # optional: ensure only one action runs at a time + steps: + - uses: actions/checkout@v4 + - uses: superfly/flyctl-actions/setup-flyctl@master + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 3da08a9..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: Release Junior - -on: - release: - types: - - created - -jobs: - publish-container: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Collect Docker metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ghcr.io/twohoursonelife/junior - tags: | - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to GitHub container registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Add version.txt - run: git describe --tags --abbrev=0 > version.txt - - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: . # Intentionally using Path context to include version.txt - push: true - tags: ${{ steps.meta.outputs.tags }}, ghcr.io/twohoursonelife/junior:latest - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - - deploy-commands: - runs-on: ubuntu-latest - environment: prod-commands - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: "20" - - - name: Install dependencies - run: npm ci - - - name: Deploy commands - run: node deploy-commands.js - env: - PROD_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }} diff --git a/Dockerfile b/Dockerfile index d839ab3..bb44962 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,4 +5,6 @@ COPY package.json bun.lockb ./ RUN bun install --frozen-lockfile --production COPY . . +RUN ls + CMD ["bun", "run", "junior.js"] diff --git a/bash.sh b/bash.sh new file mode 100644 index 0000000..5286855 --- /dev/null +++ b/bash.sh @@ -0,0 +1,3 @@ +version="1" +next_version=$(($version + 1)) +echo $next_version diff --git a/fly.toml b/fly.toml index 674b2ab..09c58e1 100644 --- a/fly.toml +++ b/fly.toml @@ -8,6 +8,8 @@ swap_size_mb = 512 [[restart]] policy = "on-failure" +# Release command, deploy commands + [[vm]] size = "shared-cpu-1x" memory = "256mb"