From 81053dc101e4327cd28ba9835f1af9576caf51d2 Mon Sep 17 00:00:00 2001 From: Mikl Wolfe Date: Mon, 26 Feb 2024 08:49:56 -0700 Subject: [PATCH 1/3] feat(client): migrate deployment to s3 --- .gitattributes | 48 ---------- .github/workflows/deploy.yml | 88 ++++++++++++++---- docs/404.html | 77 --------------- docs/CNAME | 1 - init.sh | 7 -- package.json | 4 +- {docs/public => public}/assets/favicon.ico | Bin .../public => public}/assets/img/gitlang.svg | 0 {docs/public => public}/assets/social.png | Bin {docs => public}/index.html | 2 +- stop.sh | 7 -- webpack.config.ts | 2 +- 12 files changed, 72 insertions(+), 164 deletions(-) delete mode 100644 .gitattributes delete mode 100644 docs/404.html delete mode 100644 docs/CNAME delete mode 100644 init.sh rename {docs/public => public}/assets/favicon.ico (100%) rename {docs/public => public}/assets/img/gitlang.svg (100%) rename {docs/public => public}/assets/social.png (100%) rename {docs => public}/index.html (99%) delete mode 100644 stop.sh diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 37fc46f9..00000000 --- a/.gitattributes +++ /dev/null @@ -1,48 +0,0 @@ -# See this article for reference: https://help.github.com/articles/dealing-with-line-endings/ -# Refreshing repo after line ending change: -# https://help.github.com/articles/dealing-with-line-endings/#refreshing-a-repository-after-changing-line-endings - -# Handle line endings automatically for files detected as text -# and leave all files detected as binary untouched. -* text=auto - -# -# The above will handle all files NOT found below -# -# These files are text and should be normalized (Convert crlf => lf) -# Use lf as eol for these files -.editorconfig text eol=lf -.gitignore text eol=lf -*.css text eol=lf -*.df text eol=lf -*.htm text eol=lf -*.html text eol=lf -*.java text eol=lf -*.js text eol=lf -*.json text eol=lf -*.jsp text eol=lf -*.jspf text eol=lf -*.md text eol=lf -*.properties text eol=lf -*.scss text eol=lf -*.sh text eol=lf -*.tld text eol=lf -*.ts text eol=lf -*.txt text eol=lf -*.xml text eol=lf - -# These files are binary and should be left untouched -# (binary is a macro for -text -diff) -*.class binary -*.dll binary -*.ear binary -*.gif binary -*.ico binary -*.jar binary -*.jpg binary -*.jpeg binary -*.png binary -*.so binary -*.war binary - -docs/** linguist-documentation=false diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1e50ecce..d405e09c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,31 +1,79 @@ -name: Deploy to Auth-Server +name: Deploy on: push: branches: - main + workflow_dispatch: + inputs: + environment: + type: choice + description: 'Deploy Environment' + options: + - dev + - prod + invalidate: + description: 'Invalidate CloudFront Cache' + type: boolean + default: true + jobs: deploy: name: Deploy runs-on: ubuntu-latest + env: + DIST_NAME: 'gitlang' + S3_BUCKET: 'gitlang' + DEPLOY_DIR: 'public' + steps: - - name: Configure AWS - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-2 - - - name: Create Deployment - id: deploy - env: - APP_NAME: auth-server - DEPLOY_GROUP: gitlang - run: | - aws deploy create-deployment --ignore-application-stop-failures \ - --application-name ${{ env.APP_NAME }} \ - --deployment-group-name ${{ env.DEPLOY_GROUP }} \ - --deployment-config-name CodeDeployDefault.AllAtOnce \ - --file-exists-behavior OVERWRITE \ - --github-location repository=${{ github.repository }},commitId=${{ github.sha }} + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Build + run: | + set -x + npm i + sed -i "1i console.log('Updated:', '$(TZ=PST8PDT date)')" client/src/index.ts + npm run build:prod + + - name: Configure AWS + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-2 + + - name: Sync to S3 + id: sync + run: | + aws s3 sync ${DEPLOY_DIR} s3://${S3_BUCKET} --delete + + - name: Invalidate CloudFront + id: invalidate + if: ${{ inputs.invalidate == true }} + run: | + dist_id="$(aws cloudfront list-distributions \ + --query "DistributionList.Items[?Comment=='${DIST_NAME}'].Id" \ + --output text)" + + if [ -z "$dist_id" ]; then + echo "No distribution found with comment: ${DIST_NAME}" + exit 1 + fi + + echo "Invalidating ${dist_id} for ${DIST_NAME}" + invalidation_id="$(aws cloudfront create-invalidation \ + --distribution-id "$dist_id" \ + --paths "/*" \ + --query "Invalidation.Id" \ + --output text)" + + echo "Invalidation started: ${invalidation_id}" + + aws cloudfront wait invalidation-completed \ + --distribution-id "$dist_id" \ + --id "$invalidation_id" + + echo "Invalidation completed" diff --git a/docs/404.html b/docs/404.html deleted file mode 100644 index 956f2da5..00000000 --- a/docs/404.html +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - GitLang - - - - - - - - - - - - - - - - - - -
-
- -
-
- - - diff --git a/docs/CNAME b/docs/CNAME deleted file mode 100644 index 92882ce1..00000000 --- a/docs/CNAME +++ /dev/null @@ -1 +0,0 @@ -gitlang.net \ No newline at end of file diff --git a/init.sh b/init.sh deleted file mode 100644 index 65871a3f..00000000 --- a/init.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -if [ -f "/home/ec2-user/server/init.sh" ]; then - chmod +x /home/ec2-user/server/init.sh - /home/ec2-user/server/init.sh -# else run auth-server deploy workflow -fi diff --git a/package.json b/package.json index cd5a5d94..af3636e7 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "description": "View language usage per repo or total by username", "main": "client/src/index.ts", "scripts": { - "dev": "NODE_ENV=development webpack --mode development -w", + "build:dev": "NODE_ENV=development webpack --mode development -w", + "build:prod": "NODE_ENV=production webpack --mode production", "fix": "eslint --fix '**/*'", - "prod": "NODE_ENV=production webpack --mode production", "start:client": "ts-node local/client.ts", "start:server": "ts-node local/server.ts" }, diff --git a/docs/public/assets/favicon.ico b/public/assets/favicon.ico similarity index 100% rename from docs/public/assets/favicon.ico rename to public/assets/favicon.ico diff --git a/docs/public/assets/img/gitlang.svg b/public/assets/img/gitlang.svg similarity index 100% rename from docs/public/assets/img/gitlang.svg rename to public/assets/img/gitlang.svg diff --git a/docs/public/assets/social.png b/public/assets/social.png similarity index 100% rename from docs/public/assets/social.png rename to public/assets/social.png diff --git a/docs/index.html b/public/index.html similarity index 99% rename from docs/index.html rename to public/index.html index 447854ca..14e10d63 100644 --- a/docs/index.html +++ b/public/index.html @@ -1,4 +1,4 @@ - + diff --git a/stop.sh b/stop.sh deleted file mode 100644 index 422c5662..00000000 --- a/stop.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -if [ -f "/home/ec2-user/server/stop.sh" ]; then - chmod +x /home/ec2-user/server/stop.sh - /home/ec2-user/server/stop.sh -# else run auth-server deploy workflow -fi diff --git a/webpack.config.ts b/webpack.config.ts index 57c386e3..13c092d7 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -11,7 +11,7 @@ const mode = process.env.NODE_ENV as const production = mode === 'production'; const SRC_DIR = path.join(path.resolve(), '/client/src'); -const DIST_DIR = path.join(path.resolve(), '/docs/public/dist'); +const DIST_DIR = path.join(path.resolve(), '/public/dist'); const configuration: Configuration = { entry: `${SRC_DIR}/index.ts`, From b222315e932c5402826ad55bc5a05e51303046b8 Mon Sep 17 00:00:00 2001 From: Mikl Wolfe Date: Mon, 26 Feb 2024 10:53:39 -0700 Subject: [PATCH 2/3] chore(workflow): move env to variables --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d405e09c..616f2d01 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,8 +23,8 @@ jobs: name: Deploy runs-on: ubuntu-latest env: - DIST_NAME: 'gitlang' - S3_BUCKET: 'gitlang' + DIST_NAME: ${{ vars.DIST_NAME }} + S3_BUCKET: ${{ vars.S3_BUCKET }} DEPLOY_DIR: 'public' steps: From 87399d29e4a20226ff6976bebe51292fc2a0c1f8 Mon Sep 17 00:00:00 2001 From: Mikl Wolfe Date: Mon, 26 Feb 2024 11:18:12 -0700 Subject: [PATCH 3/3] chore(workflow): remove codesee :( --- .github/workflows/codesee.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .github/workflows/codesee.yml diff --git a/.github/workflows/codesee.yml b/.github/workflows/codesee.yml deleted file mode 100644 index 1ad9abb7..00000000 --- a/.github/workflows/codesee.yml +++ /dev/null @@ -1,20 +0,0 @@ -on: - push: - branches: - - main - pull_request_target: - types: [opened, synchronize, reopened] - -name: CodeSee - -permissions: read-all - -jobs: - codesee: - runs-on: ubuntu-latest - continue-on-error: true - name: Analyse the repo with CodeSee - steps: - - uses: Codesee-io/codesee-action@v2 - with: - codesee-token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }}