Skip to content

Commit

Permalink
Split assets building out of terraform steps in github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rahearn committed Jan 10, 2025
1 parent 896535b commit 269e563
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,37 @@ permissions:
pull-requests: write

jobs:
build-assets:
name: Compile and clean assets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Compile assets
uses: ./.github/actions/compile-assets
with:
rails_env: production
save_cache: true
- name: Upload assets
uses: actions/upload-artifact@v4
with:
name: production-assets
path: public/assets

deploy:
name: Deploy to production
runs-on: ubuntu-latest
needs: build-assets
environment: production
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- name: Compile assets
uses: ./.github/actions/compile-assets
- name: Download assets
uses: actions/download-artifact@v4
with:
rails_env: production
save_cache: true
name: production-assets
path: public/assets

- name: Terraform apply
uses: dflook/terraform-apply@v1
Expand All @@ -44,3 +61,12 @@ jobs:
secret_key=${{ secrets.TERRAFORM_STATE_SECRET_ACCESS_KEY }}
bucket=${{ secrets.TERRAFORM_STATE_BUCKET_NAME }}
key=terraform.tfstate.production
- name: Save app zip for debugging
if: failure()
uses: actions/upload-artifact@v4
with:
name: app-src-apply
path: terraform/dist/src.zip
compression-level: 0
retention-days: 1
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,37 @@ permissions:
pull-requests: write

jobs:
build-assets:
name: Compile and clean assets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Compile assets
uses: ./.github/actions/compile-assets
with:
rails_env: staging
save_cache: true
- name: Upload assets
uses: actions/upload-artifact@v4
with:
name: staging-assets
path: public/assets

deploy:
name: Deploy to staging
runs-on: ubuntu-latest
needs: build-assets
environment: staging
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- name: Compile assets
uses: ./.github/actions/compile-assets
- name: Download assets
uses: actions/download-artifact@v4
with:
rails_env: staging
save_cache: true
name: staging-assets
path: public/assets

- name: Terraform apply
uses: dflook/terraform-apply@v1
Expand All @@ -44,3 +61,12 @@ jobs:
secret_key=${{ secrets.TERRAFORM_STATE_SECRET_ACCESS_KEY }}
bucket=${{ secrets.TERRAFORM_STATE_BUCKET_NAME }}
key=terraform.tfstate.staging
- name: Save app zip for debugging
if: failure()
uses: actions/upload-artifact@v4
with:
name: app-src-apply
path: terraform/dist/src.zip
compression-level: 0
retention-days: 1
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,28 @@ permissions:
pull-requests: write

jobs:
build-assets:
name: Compile and clean assets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Compile assets
uses: ./.github/actions/compile-assets
with:
rails_env: production
# you may want to enable the next line to surface issues with missing assets,
# but not until after you've deployed once and the cache has been created
# fail_on_missing_cache: true
- name: Upload assets
uses: actions/upload-artifact@v4
with:
name: production-assets
path: public/assets

terraform:
name: Terraform plan
runs-on: ubuntu-latest
needs: build-assets
environment: production
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -29,13 +48,11 @@ jobs:
with:
path: terraform

- name: Compile assets
uses: ./.github/actions/compile-assets
- name: Download assets
uses: actions/download-artifact@v4
with:
rails_env: production
# you may want to enable the next line to surface issues with missing assets,
# but not until after you've deployed once and the cache has been created
# fail_on_missing_cache: true
name: production-assets
path: public/assets

- name: terraform plan
uses: dflook/terraform-plan@v1
Expand All @@ -55,3 +72,13 @@ jobs:
secret_key=${{ secrets.TERRAFORM_STATE_SECRET_ACCESS_KEY }}
bucket=${{ secrets.TERRAFORM_STATE_BUCKET_NAME }}
key=terraform.tfstate.production
# Uncomment this step if you need to debug issues
# with mismatched app checksum between plan and apply
# - name: Save app zip for debugging
# uses: actions/upload-artifact@v4
# with:
# name: app-src-plan
# path: terraform/dist/src.zip
# compression-level: 0
# retention-days: 1
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,28 @@ permissions:
pull-requests: write

jobs:
build-assets:
name: Compile and clean assets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Compile assets
uses: ./.github/actions/compile-assets
with:
rails_env: staging
# you may want to enable the next line to surface issues with missing assets,
# but not until after you've deployed once and the cache has been created
# fail_on_missing_cache: true
- name: Upload assets
uses: actions/upload-artifact@v4
with:
name: staging-assets
path: public/assets

terraform:
name: Terraform plan
runs-on: ubuntu-latest
needs: build-assets
environment: staging
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -29,13 +48,11 @@ jobs:
with:
path: terraform

- name: Compile assets
uses: ./.github/actions/compile-assets
- name: Download assets
uses: actions/download-artifact@v4
with:
rails_env: staging
# you may want to enable the next line to surface issues with missing assets,
# but not until after you've deployed once and the cache has been created
# fail_on_missing_cache: true
name: staging-assets
path: public/assets

- name: terraform plan
uses: dflook/terraform-plan@v1
Expand All @@ -55,3 +72,13 @@ jobs:
secret_key=${{ secrets.TERRAFORM_STATE_SECRET_ACCESS_KEY }}
bucket=${{ secrets.TERRAFORM_STATE_BUCKET_NAME }}
key=terraform.tfstate.staging
# Uncomment this step if you need to debug issues
# with mismatched app checksum between plan and apply
# - name: Save app zip for debugging
# uses: actions/upload-artifact@v4
# with:
# name: app-src-plan
# path: terraform/dist/src.zip
# compression-level: 0
# retention-days: 1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ data "archive_file" "src" {
output_path = "${path.module}/dist/src.zip"
excludes = [
".git*",
"node_modules/*",
".circleci/*",
".bundle/*",
"tmp/**/*",
"terraform/*",
"log/*",
Expand Down

0 comments on commit 269e563

Please sign in to comment.