Skip to content

Commit

Permalink
ci: move pages tf logic to use modules (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
zackpollard authored Nov 26, 2024
1 parent e1e7580 commit feb645b
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 259 deletions.
81 changes: 78 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
tofu_version: '1.7.1'
tg_version: '0.69.0'
ENVIRONMENT: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}

jobs:
build:
name: Build
Expand All @@ -19,9 +24,9 @@ jobs:
matrix:
include:
- app: my.immich.app
name: my-immich
name: my
- app: buy.immich.app
name: buy-immich
name: buy

steps:
- name: Checkout code
Expand All @@ -38,7 +43,7 @@ jobs:
echo IMMICH_APP="${{ matrix.app }}" >> .env
- name: Use futopay-test
if: ${{ github.event_name == 'pull_request' }}
if: ${{ env.ENVIRONMENT == 'dev' }}
run: |
echo PUBLIC_IMMICH_PAY_HOST=https://futopay-test.azurewebsites.net >> .env
Expand All @@ -54,3 +59,73 @@ jobs:
name: build-output-${{ matrix.name }}
path: build
retention-days: 1

deploy:
name: Deploy
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
include:
- app: my.immich.app
name: my
- app: buy.immich.app
name: buy
env:
TF_VAR_app_name: ${{ matrix.name }}
TF_VAR_dist_dir: ${{ github.workspace }}/dist
TF_VAR_stage: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || '' }}
OP_SERVICE_ACCOUNT_TOKEN: ${{ github.ref == 'refs/heads/main' && secrets.OP_TF_PROD_ENV || secrets.OP_TF_DEV_ENV }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: 'Get build artifact'
uses: actions/download-artifact@v4
with:
name: 'build-output-${{ matrix.name }}'
path: '${{ github.workspace }}/build'

- name: Install 1Password CLI
uses: 1password/install-cli-action@v1

- name: Install Terragrunt
uses: eLco/setup-terragrunt@v1
with:
terragrunt_version: ${{ env.tg_version }}

- name: 'Install OpenTofu'
uses: opentofu/setup-opentofu@v1
with:
tofu_version: ${{ env.tofu_version }}
tofu_wrapper: false

- name: Deploy All
working-directory: ${{ github.workspace }}/deployment
run: op run --env-file=".env" -- terragrunt run-all apply --terragrunt-non-interactive

- name: Cloudflare Deploy Output
id: deploy-output
working-directory: ${{ github.workspace }}/deployment/modules/cloudflare/static-pages
run: |
echo "output=$(op run --no-masking --env-file='../../../.env' -- terragrunt output -json | jq -c .)" >> $GITHUB_OUTPUT
- name: Publish Frontend to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN_PAGES_UPLOAD }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: ${{ fromJson(steps.deploy-output.outputs.output).pages_project_name.value }}
directory: 'build'
branch: ${{ fromJson(steps.deploy-output.outputs.output).pages_branch.value }}
wranglerVersion: '3'

- name: Comment
uses: actions-cool/maintain-one-comment@v3
if: ${{ github.event_name == 'pull_request' }}
with:
number: ${{ github.event.number }}
body: |
📖 Preview of ${{ matrix.app }} deployed to [${{ fromJson(steps.deploy-output.outputs.output).immich_subdomain.value }}](https://${{ fromJson(steps.deploy-output.outputs.output).immich_subdomain.value }})
emojis: 'rocket'
body-include: '<!-- ${{ matrix.app }} PR URL -->'
194 changes: 0 additions & 194 deletions .github/workflows/deploy.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ node_modules
Thumbs.db

# Env
.env
.env.*
!.env.example
!.env.test
Expand Down
4 changes: 4 additions & 0 deletions deployment/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export TF_VAR_cloudflare_account_id="op://tf/cloudflare/account_id"
export TF_VAR_cloudflare_api_token="op://tf/cloudflare/api_token"
export TF_VAR_tf_state_postgres_conn_str="op://tf/tf_state/postgres_conn_str"
export TF_VAR_env=$ENVIRONMENT
13 changes: 0 additions & 13 deletions deployment/modules/cloudflare/static-pages/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 0 additions & 26 deletions deployment/modules/cloudflare/static-pages/domain.tf

This file was deleted.

5 changes: 0 additions & 5 deletions deployment/modules/cloudflare/static-pages/locals.tf

This file was deleted.

28 changes: 28 additions & 0 deletions deployment/modules/cloudflare/static-pages/pages.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module "static_pages" {
source = "git::https://github.com/immich-app/devtools.git//tf/shared/modules/cloudflare-pages?ref=main"

cloudflare_api_token = data.terraform_remote_state.api_keys_state.outputs.terraform_key_cloudflare_docs
cloudflare_account_id = data.terraform_remote_state.cloudflare_account.outputs.cloudflare_account_id

pages_project = data.terraform_remote_state.cloudflare_account.outputs.pages_projects["${var.app_name}.immich.app"]

app_name = var.app_name
stage = var.stage
env = var.env
}

output "pages_branch" {
value = module.static_pages.pages_branch
}

output "immich_subdomain" {
value = module.static_pages.branch_subdomain
}

output "pages_branch_subdomain" {
value = module.static_pages.pages_branch_subdomain
}

output "pages_project_name" {
value = module.static_pages.pages_project_name
}
Loading

0 comments on commit feb645b

Please sign in to comment.