Merge pull request #244 from fairbanksio/develop #32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Deploy' | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
infrastructure: | |
name: 'Infrastructure' | |
runs-on: ubuntu-latest | |
# Checkout the repository to the GitHub Actions runner | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token | |
- uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: "1.1.7" | |
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} | |
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. | |
- name: Terraform Init | |
working-directory: 'infrastructure' | |
run: terraform init | |
# Checks that all Terraform configuration files adhere to a canonical format | |
- name: Terraform Format | |
working-directory: 'infrastructure' | |
run: terraform fmt -check | |
# Build cluster first | |
- name: Terraform Apply | |
working-directory: 'infrastructure' | |
run: terraform apply -auto-approve | |
services: | |
name: 'Serverless' | |
needs: infrastructure | |
runs-on: ubuntu-latest | |
# Required for Github-AWS OIDC to work | |
permissions: | |
id-token: write | |
contents: read | |
# Checkout the repository to the GitHub Actions runner | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Configure AWS Credentials | |
# Basically run 'aws configure' as you would from local CLI | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: us-east-1 | |
role-to-assume: arn:aws:iam::633025216388:role/GithubActions-Fairbanksio-F5oclock | |
role-duration-seconds: 1200 # Optional duration, 20 minutes in this case | |
# Install Nodejs | |
- name: Use Node.js 20.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
# Deploy Posts Service | |
- run: npm ci | |
name: "Posts Service - Install dependencies" | |
working-directory: 'services/posts' | |
- name: "Posts Service - Deploy" | |
uses: serverless/[email protected] | |
with: | |
args: -c "cd ./services/posts && serverless deploy" | |
entrypoint: /bin/sh | |
# Deploy Scraper Service | |
- run: npm ci | |
name: "Scraper Service - Install dependencies" | |
working-directory: 'services/scraper' | |
- name: "Scraper Service - Deploy" | |
uses: serverless/[email protected] | |
with: | |
args: -c "cd ./services/scraper && serverless deploy" | |
entrypoint: /bin/sh | |
# Deploy Subreddits Service | |
- run: npm ci | |
name: "Subreddits Service - Install dependencies" | |
working-directory: 'services/subreddits' | |
- name: "Subreddits Service - Deploy" | |
uses: serverless/[email protected] | |
with: | |
args: -c "cd ./services/subreddits && serverless deploy" | |
entrypoint: /bin/sh | |
webapp: | |
name: 'Web App' | |
needs: services | |
runs-on: ubuntu-latest | |
# Required for Github-AWS OIDC to work | |
permissions: | |
id-token: write | |
contents: read | |
# Checkout the repository to the GitHub Actions runner | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Configure AWS Credentials | |
# Basically run 'aws configure' as you would from local CLI | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: us-east-1 | |
role-to-assume: arn:aws:iam::633025216388:role/GithubActions-Fairbanksio-F5oclock | |
role-duration-seconds: 1200 # Optional duration, 20 minutes in this case | |
# Install Nodejs | |
- name: Use Node.js 20.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
# Deploy Posts Service | |
- run: npm ci | |
name: "Install dependencies" | |
working-directory: 'webui' | |
- run: npm run deploy | |
name: "Deploy" | |
working-directory: 'webui' |