Skip to content

Commit

Permalink
Finish ci-cd pipeline (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
AzizMukhtorjonov authored Jun 23, 2024
1 parent a501b1c commit 49383bc
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build and deploy on Server

on:
push

env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_HOST: ${{ secrets.SERVER_HOST }}
KNOWN_HOSTS: ${{ secrets.KNOWN_HOSTS }}
DIRECTORY: "${{ vars.DIRECTORY }}/${{ github.event.repository.name }}"

jobs:
build-and-deploy:
environment: Test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}

- name: Add server to known hosts
run: |
mkdir -p ~/.ssh
echo "${{ env.KNOWN_HOSTS }}" > ~/.ssh/known_hosts
- name: Deploy on Server
run: |
ssh -t $SERVER_USER@$SERVER_HOST << EOF
if [ -d "$DIRECTORY" ]; then
rm -rf $DIRECTORY
fi
mkdir -p $DIRECTORY
cd $DIRECTORY
git clone -b cicd https://github.com/${{ github.repository }} .
git submodule init
git submodule update
echo "${{ secrets.ENVS }}" > .env
sh deploy.sh
rm -rf $DIRECTORY
EOF
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "deploy"]
path = deploy
url = [email protected]:JollyRojer1512/deploy.git
[submodule "ci-cd"]
path = ci-cd
url = [email protected]:JollyRojer1512/ci-cd.git
2 changes: 1 addition & 1 deletion applications/main.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"APP_NAME": "main",
"NPM_SCRIPT": "start",
"ENV_FILE": ".env.docker",
"ENV_FILE": ".env",
"APP_PORT": 1512
}
1 change: 1 addition & 0 deletions ci-cd
Submodule ci-cd added at 51affe
1 change: 0 additions & 1 deletion deploy
Submodule deploy deleted from 340b08
2 changes: 1 addition & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONFIG_FILE=applications/main bash deploy/deploy.sh
CONFIG_FILE=applications/main bash ci-cd/deploy.sh
2 changes: 1 addition & 1 deletion test/components/config/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EnvironmentNotDefined } from 'src/components/errors';

describe('Env', () => {
it('Use .env if other env_file is not provided', () => {
const originalEnv = process.env;
const originalEnv = process.env ?? '.env.test';
process.env = {};
const env = new Env();
expect(env.get('MAIN_APP_HOST')).toBe('localhost');
Expand Down

0 comments on commit 49383bc

Please sign in to comment.