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

Add a guide on deploying through Github Actions #1291

Open
jwoertink opened this issue Apr 13, 2024 · 0 comments
Open

Add a guide on deploying through Github Actions #1291

jwoertink opened this issue Apr 13, 2024 · 0 comments
Labels
guides:deployments Guides on how to deploy to production

Comments

@jwoertink
Copy link
Member

I have several apps that now deploy through Github actions. The config setup will change based on where you're deploying, but we can use this overall structure for a starter template to guide people.

name: PROJECT_NAME Deploy

on:
  push:
    branches:
      - production

jobs:
  PROJECT_NAME:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Crystal
        uses: crystal-lang/install-crystal@v1
        with:
          crystal: CRYSTAL_VERSION

      - name: Cache Node modules
        uses: actions/cache@v3
        with:
          path: "**/node_modules"
          key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

      - name: Cache App Binary
        uses: actions/cache@v4
        with:
          path: |
            ./bin
            ./public
          key: ${{ github.sha }}-app

      - name: Copy .env
        run: |
          cp .env.production .env

      - name: Build Assets
        env:
          NODE_OPTIONS: --max_old_space_size=4096 --openssl-legacy-provider
        run: |
          yarn
          yarn prod

      - name: Build App
        run: |
          shards build PROJECT_NAME --production --release --skip-postinstall --skip-executables

  worker:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Crystal
        uses: crystal-lang/install-crystal@v1
        with:
          crystal: CRYSTAL_VERSION

      - name: Cache Worker Binary
        uses: actions/cache@v4
        with:
          path: ./bin/worker
          key: ${{ github.sha }}-worker

      - name: Build Worker
        run: |
          shards build worker --production --release --skip-postinstall --skip-executables

  deploy:
    runs-on: ubuntu-latest
    needs: [PROJECT_NAME, worker]
    steps:
      - uses: actions/checkout@v4

      - name: Cache App Binary
        uses: actions/cache@v4
        with:
          path: |
            ./bin
            ./public
          key: ${{ github.sha }}-app

      - name: Cache Worker Binary
        uses: actions/cache@v4
        with:
          path: ./bin/worker
          key: ${{ github.sha }}-worker

      - name: Stage Deployment Files
        run: |
          echo 'setup your application for deployment'

      - name: Get timestamp
        uses: gerred/actions/current-time@master
        id: current-time

      - name: Run string replace
        uses: frabert/replace-string-action@master
        id: format-time
        with:
          pattern: '[:\.]+'
          string: "${{ steps.current-time.outputs.time }}"
          replace-with: "-"
          flags: "g"

      - name: Deploy files
        run: |
          echo 'run your deployment code here'

      - name: Deployed successfully!
        run: echo 'App deploy complete'

The guide could even show an example of deploying to a staging environment and building out a seeds binary using some custom compile flags like -Dstaging.

@jwoertink jwoertink added the guides:deployments Guides on how to deploy to production label Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guides:deployments Guides on how to deploy to production
Projects
None yet
Development

No branches or pull requests

1 participant