diff --git a/.github/workflows/Deploy-Server.yaml b/.github/workflows/Deploy-Server.yaml index 48c2f28..11def1c 100644 --- a/.github/workflows/Deploy-Server.yaml +++ b/.github/workflows/Deploy-Server.yaml @@ -23,7 +23,18 @@ jobs: - name: Push Docker image run: docker push seanyee1227/pushandpull-server:latest - - name: Deploy to server via SSH + - name: Copy compose file to server + uses: appleboy/scp-action@v0.1.7 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + port: ${{ secrets.SSH_PORT }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + source: "PushAndPull/deploy/compose.prod.yaml" + target: "~/deploy/" + strip_components: 2 + + - name: Deploy via Docker Compose uses: appleboy/ssh-action@v0.1.10 with: host: ${{ secrets.SSH_HOST }} @@ -31,17 +42,16 @@ jobs: port: ${{ secrets.SSH_PORT }} key: ${{ secrets.SSH_PRIVATE_KEY }} script: | - docker pull seanyee1227/pushandpull-server:latest - docker stop pushandpull-server || true - docker rm pushandpull-server || true - docker run -d \ - --name pushandpull-server \ - --restart unless-stopped \ - -p 21754:80 \ - -e ASPNETCORE_URLS=http://+:80 \ - -e ASPNETCORE_ENVIRONMENT=Production \ - -e "ConnectionStrings__Default=${{ secrets.DB_CONNECTION_STRING }}" \ - seanyee1227/pushandpull-server:latest + mkdir -p ~/deploy + + printf 'DB_CONNECTION_STRING=%s\nREDIS_CONNECTION_STRING=%s\nSTEAM_WEB_API_KEY=%s\n' \ + "${{ secrets.DB_CONNECTION_STRING }}" \ + "${{ secrets.REDIS_CONNECTION_STRING }}" \ + "${{ secrets.STEAM_WEB_API_KEY }}" \ + > ~/deploy/.env + + docker compose -f ~/deploy/compose.prod.yaml --env-file ~/deploy/.env pull + docker compose -f ~/deploy/compose.prod.yaml --env-file ~/deploy/.env up -d sleep 5 docker ps | grep pushandpull-server diff --git a/PushAndPull/PushAndPull/appsettings.Production.json b/PushAndPull/PushAndPull/appsettings.Production.json index 87d5b2c..50154f6 100644 --- a/PushAndPull/PushAndPull/appsettings.Production.json +++ b/PushAndPull/PushAndPull/appsettings.Production.json @@ -10,7 +10,7 @@ "AppId": 480 }, "Redis": { - "ConnectionString": "127.0.0.1:6379,abortConnect=false" + "ConnectionString": "" }, "ConnectionStrings": { "Default": "" diff --git a/PushAndPull/PushAndPull/appsettings.json b/PushAndPull/PushAndPull/appsettings.json index 1ae86e3..30d31bc 100644 --- a/PushAndPull/PushAndPull/appsettings.json +++ b/PushAndPull/PushAndPull/appsettings.json @@ -7,7 +7,7 @@ }, "AllowedHosts": "*", "Steam": { - "WebApiKey": "Steam-ApiKey", + "WebApiKey": "", "AppId": 480 }, "ConnectionStrings": { diff --git a/PushAndPull/deploy/compose.prod.yaml b/PushAndPull/deploy/compose.prod.yaml index a8de0fd..5707b7c 100644 --- a/PushAndPull/deploy/compose.prod.yaml +++ b/PushAndPull/deploy/compose.prod.yaml @@ -1,27 +1,18 @@ name: pushandpull-prod services: - pushpull-db: - image: postgres:17 - container_name: pushpull-db - environment: - POSTGRES_DB: pushpull - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - volumes: - - postgres_data:/var/lib/postgresql/data - restart: unless-stopped - - pushpull-redis: + pushandpull-redis: image: redis:7-alpine - container_name: pushpull-redis + container_name: pushandpull-redis volumes: - redis_data:/data + networks: + - pushandpull-network restart: unless-stopped - pushpull-server: + pushandpull-server: image: seanyee1227/pushandpull-server:latest - container_name: pushpull-server + container_name: pushandpull-server ports: - "21754:80" environment: @@ -31,10 +22,14 @@ services: - Redis__ConnectionString=${REDIS_CONNECTION_STRING} - Steam__WebApiKey=${STEAM_WEB_API_KEY} depends_on: - - pushpull-db - - pushpull-redis + - pushandpull-redis + networks: + - pushandpull-network restart: unless-stopped volumes: - postgres_data: redis_data: + +networks: + pushandpull-network: + driver: bridge