adds workflow
This commit is contained in:
parent
0a6ad0a419
commit
81f7fa5a9a
5 changed files with 104 additions and 2 deletions
37
.github/scripts/deploy.sh
vendored
Normal file
37
.github/scripts/deploy.sh
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
DOCKER_REGISTRY="ghcr.io"
|
||||
DOCKER_USERNAME="pb-coding"
|
||||
DOCKER_IMAGE_NAME="skyjo-be"
|
||||
CONTAINER_NAME="skyjo-be"
|
||||
TARGET_DIRECTORY="/home/pb1497/deployments/$CONTAINER_NAME"
|
||||
DOCKER_NETWORK="swag_net"
|
||||
|
||||
# Authenticate with Docker registry
|
||||
echo "Authenticating with Docker registry..."
|
||||
docker login -u $DOCKER_USERNAME --password $GITHUB_TOKEN $DOCKER_REGISTRY
|
||||
|
||||
# Pull the latest Docker image
|
||||
echo "Pulling the latest Docker image..."
|
||||
docker pull $DOCKER_REGISTRY/$DOCKER_USERNAME/$DOCKER_IMAGE_NAME:latest
|
||||
|
||||
cd $TARGET_DIRECTORY
|
||||
|
||||
# Stop and remove the existing container if it exists
|
||||
if [ "$(docker ps -aq -f name=$CONTAINER_NAME)" ]; then
|
||||
echo "Stopping and removing the existing container..."
|
||||
docker stop $CONTAINER_NAME
|
||||
docker rm $CONTAINER_NAME
|
||||
fi
|
||||
|
||||
# Run the new Docker container
|
||||
echo "Starting a new container from the latest image..."
|
||||
docker run -d \
|
||||
--name $CONTAINER_NAME \
|
||||
--network $DOCKER_NETWORK \
|
||||
-v $TARGET_DIRECTORY:/app \
|
||||
$DOCKER_REGISTRY/$DOCKER_USERNAME/$DOCKER_IMAGE_NAME:latest
|
||||
|
||||
echo "Deployment complete."
|
||||
49
.github/workflows/deploy.yml
vendored
Normal file
49
.github/workflows/deploy.yml
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
name: Build and push docker image and deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build_and_push:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Log in to Github Container registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ghcr.io/${{ github.actor }}/skyjo-be:latest
|
||||
|
||||
deploy:
|
||||
needs: build_and_push
|
||||
if: ${{ success() }}
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Deploy to target server
|
||||
env:
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
echo "$DEPLOY_KEY" > deploy_key.pem
|
||||
chmod 600 deploy_key.pem
|
||||
scp -i deploy_key.pem -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null .github/scripts/deploy.sh $DEPLOY_USER@$DEPLOY_HOST:/tmp/
|
||||
ssh -i deploy_key.pem -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $DEPLOY_USER@$DEPLOY_HOST "GITHUB_TOKEN=$GITHUB_TOKEN bash -s" < /tmp/deploy.sh
|
||||
rm -f deploy_key.pem
|
||||
16
Dockerfile
Normal file
16
Dockerfile
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
FROM node:18
|
||||
LABEL org.opencontainers.image.source https://github.com/pb-coding/skyjo-be
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN npm run build
|
||||
|
||||
EXPOSE 3001
|
||||
|
||||
CMD ["npm", "run", "start"]
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev": "ts-node src/server.ts",
|
||||
"build": "prisma generate && tsc",
|
||||
"build": "tsc",
|
||||
"start": "node dist/server.js"
|
||||
},
|
||||
"repository": {
|
||||
|
|
|
|||
|
|
@ -386,7 +386,7 @@ export class Game {
|
|||
return {
|
||||
...player,
|
||||
cards: cards.map((card: Card, index: number) => {
|
||||
// unknown cards are obfuscated to 0
|
||||
// unknown cards are obfuscated to X
|
||||
return {
|
||||
id: player.knownCardPositions[index] ? card.id : 0,
|
||||
value: player.knownCardPositions[index] ? card.value : "X",
|
||||
|
|
|
|||
Loading…
Reference in a new issue