Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup CD #28

Merged
merged 20 commits into from
Apr 24, 2023
32 changes: 27 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ jobs:

- name: Setup secrets
env:
USER: ${{ secrets.KWASOW_USERNAME }}
PASSWORD: ${{ secrets.KWASOW_PASSWORD }}
USER: ${{ secrets.DB_USERNAME }}
PASSWORD: ${{ secrets.DB_PASSWORD }}
run: |
echo "export const user = '$USER';export const password = '$PASSWORD';" > src/secrets.ts

- name: Setup SSH tunnel
env:
USER: ${{ secrets.KWASOW_USERNAME }}
PASSWORD: ${{ secrets.KWASOW_PASSWORD }}
HOST: ${{ secrets.SERVER_HOST }}
USER: ${{ secrets.SERVER_USERNAME }}
KEY: ${{ secrets.SERVER_KEY }}
run: |
eval $(ssh-agent -s)
echo "$KEY" | tr -d '\r' | ssh-add -
mkdir -p ~/.ssh
echo "StrictHostKeyChecking no" >> ~/.ssh/config
sshpass -p $PASSWORD ssh -fN -L 5432:lkdb:5432 $USER@students.mimuw.edu.pl
ssh -fN -L 5432:localhost:5432 ${USER}@${HOST}

- name: Add firebase service account json file
env:
Expand All @@ -46,3 +49,22 @@ jobs:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@v3

# Run deploy on push to main only if tests succeed"
deploy:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy using ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_KEY }}
port: 22
script: |
cd ~/Git/pokerio-server
git pull origin main
yarn
yarn production
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"lint": "eslint --ext '.js,.ts,.tsx' src/",
"pretty": "yarn prettier --write .",
"pretty-check": "yarn prettier --check src/",
"prepare": "husky install"
"prepare": "husky install",
"production": "pm2 delete pokerio-server || : && pm2 start dist/index.js --name pokerio-server"
},
"devDependencies": {
"@types/express": "^4.17.17",
Expand All @@ -25,6 +26,7 @@
"eslint-plugin-promise": "^6.0.0",
"husky": "^8.0.0",
"lint-staged": "^13.2.0",
"pm2": "^5.3.0",
"prettier": "2.8.4",
"supertest": "^6.3.3",
"ts-jest": "^29.0.5",
Expand Down
2 changes: 1 addition & 1 deletion src/databaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function getClient(): any {
return new Client({
user,
password,
database: 'bd',
database: 'pokerio',
port: 5432,
host: 'localhost',
})
Expand Down
Loading