Skip to content

Commit

Permalink
Test shared deploy and Docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
Guysnacho committed Oct 18, 2024
1 parent 23c52df commit 510222c
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
93 changes: 93 additions & 0 deletions .github/workflows/bundle_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
on:
push:
branches:
- "34-Throw-it-in-a-box!"
permissions:
pull-requests: write
name: 🌱 Apply, Build, Deploy 🌿
jobs:
TF-Apply:
name: 🏗️ Apply Infra
runs-on: ubuntu-latest
# https://stackoverflow.com/questions/59175332/using-output-from-a-previous-job-in-a-new-one-in-a-github-action
outputs:
apigw: ${{steps.APIGW.outputs.NEXT_PUBLIC_APIGW}}
steps:
- name: Check Out
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
terraform_version: 1.9.2
- name: Look around nd Init 👁️👁️
run: |
echo Looking around 👁️👁️
ls
cd terraform
echo Looking around 👁️👁️
ls
terraform init
- name: 🏗️ Terraform Apply
run: |
cd terraform
terraform apply -var="bucket-name=${{ secrets.S3_BUCKET }}" -var="db-name=${{ secrets.DB_NAME }}" -var="db-username=${{ secrets.DB_USER }}" -auto-approve
- run: echo ${{ steps.plan.outputs.stdout }}
- run: echo ${{ steps.plan.outputs.stderr }}
- run: echo ${{ steps.plan.outputs.exitcode }}
- name: Fetch API GW
id: APIGW
run: |
cd terraform
echo "NEXT_PUBLIC_APIGW=$(terraform output -raw api-route)" >> $GITHUB_OUTPUT
web-deploy:
name: 💫 Deploy
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
needs: ["TF-Apply"]
steps:
- name: Set up Docker Buildx and Checkout
uses: docker/setup-buildx-action@v3
- name: Use Node.js
uses: actions/setup-node@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
aws-region: us-west-2
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}}
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}}

- name: 😪 Installing Dependencies
run: |
cd web
npm install
- name: ⚗️ Write env variables
run: |
cd web
echo "NEXT_PUBLIC_APIGW=${{needs.TF-Apply.outputs.apigw}}" > .env
- name: 🔨 Build Static Project
run: |
cd web
STATIC=1 npm run build
- name: 🐳 Build Image
run: |
cd web
npm run build
- name: 🚀 Upload Package
run: |
aws s3 sync ./web/out s3://${{ secrets.S3_BUCKET }}/ --region us-west-2
aws s3 sync ./web/out s3://${{ secrets.S3_BUCKET }}-failover/ --region us-west-2
- name: 🌩️ Upload Image
uses: docker/build-push-action@v6
with:
file: ./web/Dockerfile
push: false # if we wanted to push the image to DockerHub
add-hosts: 3000:3000
tags: user/app:latest
5 changes: 4 additions & 1 deletion web/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
output: "standalone",
output: process.env.STATIC ? "export" : "standalone",
images: {
unoptimized: process.env.STATIC ? true : false,
},
};

export default nextConfig;

0 comments on commit 510222c

Please sign in to comment.