Skip to content

Commit

Permalink
add step to generate env.json
Browse files Browse the repository at this point in the history
  • Loading branch information
rantanevich committed Mar 15, 2024
1 parent 3cedd65 commit 639d4ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 80 deletions.
69 changes: 5 additions & 64 deletions .github/actions/deploy/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Frontend Deploy

inputs:
workdir:
default: '.'
webroot:
description: The root directory of the web server that will be used to search for a file
required: true
Expand All @@ -16,15 +18,6 @@ inputs:
ssh_password:
description: SSH password
required: true
lib_latest:
description: Install the latest version of @staketab/lib
default: false
keep_source_maps:
description: Keep JavaScript Source Maps
default: true
nodejs_version:
description: Node.js version
default: 18.x
github_token:
description: GitHub Personal Access Token (PAT)
required: true
Expand All @@ -34,7 +27,6 @@ runs:
steps:
- name: Login to GitHub Packages
shell: sh
working-directory: ./
run: |
cat > .npmrc <<-EOF
//npm.pkg.github.com/:_authToken=${{ inputs.github_token }}
Expand All @@ -54,20 +46,18 @@ runs:
run_install: false

- name: Install NPM dependencies
working-directory: ui
working-directory: ${{ inputs.workdir }}
shell: sh
run: pnpm install

- name: Build project
working-directory: ui
working-directory: ${{ inputs.workdir }}
shell: sh
run: pnpm run build

- name: Deploy compiled project to the remote server
shell: sh
run: |
set -x
sshpass -p "${{ inputs.ssh_password }}" \
ssh ${{ inputs.ssh_username }}@${{ inputs.ssh_hostname }} rm -rf ${{ inputs.webroot }}/*
Expand All @@ -77,56 +67,7 @@ runs:
--verbose \
--human-readable \
--delete-before \
ui/ ${{ inputs.ssh_username }}@${{ inputs.ssh_hostname }}:${{ inputs.webroot }}/
${{ inputs.workdir }} ${{ inputs.ssh_username }}@${{ inputs.ssh_hostname }}:${{ inputs.webroot }}/
sshpass -p "${{ inputs.ssh_password }}" \
ssh ${{ inputs.ssh_username }}@${{ inputs.ssh_hostname }} "sudo systemctl restart ${{ inputs.systemd_service }}"
# - name: Copy Files to Server
# shell: sh
# run: |
# sshpass -p "${{ inputs.ssh_password }}" \
# rsync \
# --archive \
# --verbose \
# --human-readable \
# ./ui/ ${{ inputs.ssh_username }}@${{ inputs.ssh_hostname }}:${{ inputs.webroot }}

# - name: Install Dependencies and Build on Server
# shell: sh
# run: |
# sshpass -p "${{ inputs.ssh_password }}" ssh ${{ inputs.ssh_username }}@${{ inputs.ssh_hostname }} "\
# cd ${{ inputs.webroot }} && \
# npm install --legacy-peer-deps && \
# npm install -g next && \
# npm install react --legacy-peer-deps && \
# npm install react-dom --legacy-peer-deps && \
# npm install -g pnpm && \
# pnpm i && \
# pnpm run build
# "
# sshpass -p "${{ inputs.ssh_password }}" ssh ${{ inputs.ssh_username }}@${{ inputs.ssh_hostname }} "sudo find ${{ inputs.webroot }} -not -user root -or -not -group root -exec chown root:root '{}' +"

# - name: Deploy Compiled Project
# shell: sh
# run: |
# sshpass -p "${{ inputs.ssh_password }}" ssh ${{ inputs.ssh_username }}@${{ inputs.ssh_hostname }} "\
# rsync \
# --archive \
# --verbose \
# --human-readable \
# --delete-before \
# ${{ inputs.keep_source_maps == 'false' && '--exclude=\"*.map\"' || '' }} ${{ inputs.temproot }}/ ${{ inputs.webroot }}/
# "

# - name: Restart Next.js service on the server
# shell: sh
# run: |
# sshpass -p "${{ inputs.ssh_password }}" ssh ${{ inputs.ssh_username }}@${{ inputs.ssh_hostname }} "sudo systemctl restart ${{ inputs.serv }}"

# - name: Remove Temporary Directory on the Server
# shell: sh
# run: |
# sshpass -p "${{ inputs.ssh_password }}" ssh ${{ inputs.ssh_username }}@${{ inputs.ssh_hostname }} "\
# rm -rf ${{ inputs.temproot }}/ \
# "
26 changes: 10 additions & 16 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ jobs:
# path: .github/actions
# token: ${{ secrets.GH_TOKEN }}

# - name: calculate environment
# run: |
# pull_request_branch=${{ github.base_ref }}
# dispatch_branch=${{ github.event.inputs.environment }}
# echo "ENVIRONMENT=${pull_request_branch:-$dispatch_branch}" >> $GITHUB_ENV

- name: Settings
uses: kanga333/variable-mapper@v0.2.2
id: settings
Expand All @@ -43,39 +37,39 @@ jobs:
"^(t-names|deploy-pipeline)$": {
"node_env": "development",
"webroot": "/var/www/test/names",
"temproot": "/var/www/test/tmp-names",
"ssh_hostname": "${{ secrets.FRONT_SCORE_IP }}",
"ssh_password": "${{ secrets.FRONT_SCORE_SSH }}",
"lib_latest": "true",
"keep_source_maps": "false",
"systemd_service": "names-test.service"
},
"^main$": {
"node_env": "production",
"webroot": "/var/www/prod/names",
"temproot": "/var/www/prod/tmp-names",
"ssh_hostname": "${{ secrets.FRONT_SCORE_IP }}",
"ssh_password": "${{ secrets.FRONT_SCORE_SSH }}",
"lib_latest": "false",
"keep_source_maps": "false",
"systemd_service": "names.service"
}
}
export_to: output,log
mode: fill

- name: generate env.json
run: |
cat > ui/env.json <<-EOF
{
"NEXT_PUBLIC_API_URL": "${{ secrets.NEXT_PUBLIC_API_URL }}",
"NEXT_PUBLIC_API_KEY": "${{ secrets.NEXT_PUBLIC_API_KEY }}"
}
EOF
- name: Deploy React.js
uses: ./.github/actions/deploy
with:
workdir: ui
webroot: ${{ steps.settings.outputs.webroot }}
temproot: ${{ steps.settings.outputs.temproot }}
systemd_service: ${{ steps.settings.outputs.systemd_service }}
ssh_hostname: ${{ steps.settings.outputs.ssh_hostname }}
ssh_username: ${{ secrets.SERVER_USERNAME }}
ssh_password: ${{ steps.settings.outputs.ssh_password }}
lib_latest: ${{ steps.settings.outputs.lib_latest }}
keep_source_maps: ${{ steps.settings.outputs.keep_source_maps }}
nodejs_version: 18.x
github_token: ${{ secrets.GH_TOKEN }}
env:
REACT_APP_ENVIRONMENT: ${{ steps.settings.outputs.node_env }}

0 comments on commit 639d4ec

Please sign in to comment.