Skip to content

Commit

Permalink
ci: 🎡 add socios-oauth2 deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
abcfy2 committed Sep 13, 2023
1 parent 9e309e8 commit 542d0a8
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
node-version: [16.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-to-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
node-version: [16.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ecommerce-store-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
name: ecommerce-store-website
path: ecommerce-store-website/out/
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
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 }}
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/socios-auth2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: "socios-oauth2 CI"

on:
push:
branches:
- main
- staging
pull_request:
branches:
- "*"
workflow_dispatch:

env:
PROJ_PATH: socios-oauth2
DEPLOY_URL: https://socios-oauth2.tokenscript.org/

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
cache-dependency-path: ${{ env.PROJ_PATH }}/package-lock.json
- run: |
echo -n "Node version: "
node -v
echo -n "Npm version: "
npm -v
- name: build
run: |
cd "${PROJ_PATH}"
npm ci
npm run build
- uses: actions/upload-artifact@v3
with:
name: socios-oauth2
path: ${{ env.PROJ_PATH }}/dist/

deploy:
runs-on: ubuntu-latest
environment:
name: socios-oauth2
url: ${{ env.DEPLOY_URL }}
needs:
- build
if: ${{ contains(
fromJson('["push", "workflow_dispatch"]'),
github.event_name) &&
contains(
fromJson('["staging"]'),
github.ref_name)
}}
steps:
- uses: actions/download-artifact@v3
with:
name: socios-oauth2
path: ${{ env.PROJ_PATH }}/dist/
- name: Deploy to EC2
uses: easingthemes/ssh-deploy@v4
with:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
REMOTE_HOST: 54.177.203.8
REMOTE_USER: ubuntu
ARGS: "-aPz --delete"
SOURCE: "${{ env.PROJ_PATH }}/dist/"
TARGET: /opt/services/socios-oauth2/
SCRIPT_AFTER: |
sudo systemctl restart socios-oauth2
- name: check deploy
run: |
for i in $(seq 15); do
curl -sfL --connect-timeout 30 "${DEPLOY_URL}" && exit || sleep 5
done && exit 1
4 changes: 2 additions & 2 deletions .github/workflows/token-outlet-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
name: token-outlet-website
path: token-outlet-website/build/
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
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 }}
Expand Down
3 changes: 2 additions & 1 deletion socios-oauth2/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "dotenv/config";

const app = express();
const port = 5000;
const hostname = process.env.HOST;

// ES6 solution for __dirname
const __filename = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -68,4 +69,4 @@ app.get("/user-nfts", cors(corsOptions), async (request, response) => {
response.json(output);
});

app.listen(port, () => console.info(`App listening on port ${port}`));
app.listen(port, hostname, () => console.info(`App listening ${hostname ?? ''} on port ${port}`));

0 comments on commit 542d0a8

Please sign in to comment.