Skip to content

Commit 46b5cb5

Browse files
committed
Updated packages + GitHub actions
1 parent 86f5276 commit 46b5cb5

4 files changed

Lines changed: 235 additions & 104 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Deploy to VPS
2+
3+
# Workflow for automatic deployment of an application to VPS when pushing to the master branch
4+
5+
on:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
deploy:
12+
name: Deploy Application
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0 # Download full history for potential change comparisons
20+
21+
- name: Setup SSH and Deploy
22+
uses: appleboy/ssh-action@master
23+
with:
24+
host: ${{ secrets.VPS_HOST }}
25+
username: ${{ secrets.VPS_USERNAME }}
26+
key: ${{ secrets.VPS_SSH_KEY }}
27+
port: ${{ secrets.VPS_PORT }}
28+
# Upload files to the server
29+
envs: GITHUB_SHA
30+
script_stop: true # Stop executing further commands on error
31+
script: |
32+
# Check if project directory exists and if it's a git repository
33+
export ACTUAL_PATH="${{ secrets.PROJECT_PATH }}/trek-server"
34+
if [ -d "$ACTUAL_PATH/.git" ]; then
35+
echo "Git repository exists, updating repository..."
36+
cd $ACTUAL_PATH
37+
git pull origin master
38+
else
39+
echo "Git repository doesn't exist, setting up from scratch..."
40+
# Create PROJECT_PATH if it doesn't exist
41+
mkdir -p "$ACTUAL_PATH"
42+
cd "$ACTUAL_PATH"
43+
44+
# Initialize as git repository and set remote
45+
git init
46+
git remote add origin https://github.com/jsfraz/trek-server.git
47+
48+
# Fetch and checkout master branch
49+
git fetch origin master
50+
git checkout -f -B master origin/master
51+
fi
52+
53+
echo "Creating data directory if it doesn't exist..."
54+
mkdir -p data
55+
56+
- name: Deploy
57+
uses: appleboy/ssh-action@master
58+
with:
59+
host: ${{ secrets.VPS_HOST }}
60+
username: ${{ secrets.VPS_USERNAME }}
61+
key: ${{ secrets.VPS_SSH_KEY }}
62+
port: ${{ secrets.VPS_PORT }}
63+
script_stop: true # Stops executing further commands in case of error
64+
script: |
65+
export ACTUAL_PATH="${{ secrets.PROJECT_PATH }}/trek-server"
66+
cd "$ACTUAL_PATH"
67+
68+
# Check if docker-compose.yml exists (sanity check)
69+
if [ ! -f docker-compose.yml ]; then
70+
echo "Error: docker-compose.yml not found in $ACTUAL_PATH"
71+
echo "Current directory contents:"
72+
ls -la
73+
exit 1
74+
fi
75+
76+
# Create .env file
77+
echo "Creating .env file..."
78+
cat > .env << EOL
79+
SERVER_URL=${{ secrets.SERVER_URL }}
80+
GIN_MODE=release
81+
POSTGRES_USER=${{ secrets.POSTGRES_USER }}
82+
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
83+
POSTGRES_PORT=${{ secrets.POSTGRES_PORT }}
84+
POSTGRES_DB=${{ secrets.POSTGRES_DB }}
85+
ACCESS_TOKEN_SECRET=${{ secrets.ACCESS_TOKEN_SECRET }}
86+
ACCESS_TOKEN_LIFESPAN=${{ secrets.ACCESS_TOKEN_LIFESPAN }}
87+
TRACKER_TOKEN_SECRET=${{ secrets.TRACKER_TOKEN_SECRET }}
88+
SUPERUSER_USERNAME=${{ secrets.SUPERUSER_USERNAME }}
89+
SUPERUSER_PASSWORD=${{ secrets.SUPERUSER_PASSWORD }}
90+
CLIENT_URL=${{ secrets.CLIENT_URL }}
91+
EOL
92+
93+
# Stop running containers
94+
echo "Stopping current containers..."
95+
docker compose -f docker-compose.yml --env-file .env down || echo "No containers to stop"
96+
97+
# Build and start containers
98+
echo "Building and starting containers..."
99+
docker compose -f docker-compose.yml --env-file .env up -d --build
100+
101+
# Wait for the service to start
102+
echo "Waiting for service to start..."
103+
sleep 10
104+
105+
# Verify containers are running
106+
echo "Checking container status..."
107+
docker compose -f docker-compose.yml ps
108+
109+
- name: Notify Deployment Status
110+
# This step will always run to report status
111+
if: always()
112+
run: |
113+
if [ "${{ job.status }}" == "success" ]; then
114+
echo "Deployment completed successfully!"
115+
else
116+
echo "Deployment failed! Please check logs for details."
117+
fi

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use the official Golang image as the base image
2-
FROM golang:1.23.2-alpine AS build
2+
FROM golang:1.26.2-alpine AS build
33

44
# Set the working directory inside the container
55
WORKDIR /app

go.mod

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,63 @@
11
module jsfraz/trek-server
22

3-
go 1.23.2
3+
go 1.26.2
44

55
require (
6-
github.com/gin-contrib/cors v1.7.2
7-
github.com/gin-gonic/gin v1.10.0
8-
github.com/go-playground/validator/v10 v10.22.1
9-
github.com/golang-jwt/jwt/v5 v5.2.1
6+
github.com/gin-contrib/cors v1.7.7
7+
github.com/gin-gonic/gin v1.12.0
8+
github.com/go-playground/validator/v10 v10.30.2
9+
github.com/golang-jwt/jwt/v5 v5.3.1
1010
github.com/googollee/go-socket.io v1.7.0
11-
github.com/loopfz/gadgeto v0.11.4
12-
github.com/wI2L/fizz v0.22.0
13-
golang.org/x/crypto v0.28.0
14-
gorm.io/driver/postgres v1.5.9
15-
gorm.io/gorm v1.25.12
11+
github.com/loopfz/gadgeto v0.11.6
12+
github.com/wI2L/fizz v0.23.0
13+
golang.org/x/crypto v0.50.0
14+
gorm.io/driver/postgres v1.6.0
15+
gorm.io/gorm v1.31.1
1616
)
1717

1818
require (
19-
github.com/bytedance/sonic v1.12.3 // indirect
20-
github.com/bytedance/sonic/loader v0.2.0 // indirect
21-
github.com/cloudwego/base64x v0.1.4 // indirect
22-
github.com/cloudwego/iasm v0.2.0 // indirect
23-
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
24-
github.com/gin-contrib/sse v0.1.0 // indirect
19+
github.com/bytedance/gopkg v0.1.4 // indirect
20+
github.com/goccy/go-yaml v1.19.2 // indirect
21+
github.com/quic-go/qpack v0.6.0 // indirect
22+
github.com/quic-go/quic-go v0.59.0 // indirect
23+
go.mongodb.org/mongo-driver/v2 v2.6.0 // indirect
24+
go.yaml.in/yaml/v2 v2.4.4 // indirect
25+
)
26+
27+
require (
28+
github.com/bytedance/sonic v1.15.1 // indirect
29+
github.com/bytedance/sonic/loader v0.5.1 // indirect
30+
github.com/cloudwego/base64x v0.1.7 // indirect
31+
github.com/gabriel-vasile/mimetype v1.4.13 // indirect
32+
github.com/gin-contrib/sse v1.1.1 // indirect
2533
github.com/go-playground/locales v0.14.1 // indirect
2634
github.com/go-playground/universal-translator v0.18.1 // indirect
27-
github.com/goccy/go-json v0.10.3 // indirect
35+
github.com/goccy/go-json v0.10.6 // indirect
2836
github.com/gofrs/uuid v4.4.0+incompatible // indirect
29-
github.com/gomodule/redigo v1.9.2 // indirect
37+
github.com/gomodule/redigo v1.9.3 // indirect
3038
github.com/google/uuid v1.6.0 // indirect
3139
github.com/gorilla/websocket v1.5.3 // indirect
3240
github.com/jackc/pgpassfile v1.0.0 // indirect
3341
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
34-
github.com/jackc/pgx/v5 v5.7.1 // indirect
42+
github.com/jackc/pgx/v5 v5.9.2 // indirect
3543
github.com/jackc/puddle/v2 v2.2.2 // indirect
3644
github.com/jinzhu/inflection v1.0.0 // indirect
3745
github.com/jinzhu/now v1.1.5 // indirect
3846
github.com/json-iterator/go v1.1.12 // indirect
3947
github.com/kelseyhightower/envconfig v1.4.0
40-
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
48+
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
4149
github.com/leodido/go-urn v1.4.0 // indirect
42-
github.com/mattn/go-isatty v0.0.20 // indirect
50+
github.com/mattn/go-isatty v0.0.22 // indirect
4351
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4452
github.com/modern-go/reflect2 v1.0.2 // indirect
45-
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
53+
github.com/pelletier/go-toml/v2 v2.3.1 // indirect
4654
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
47-
github.com/ugorji/go/codec v1.2.12 // indirect
48-
golang.org/x/arch v0.11.0 // indirect
49-
golang.org/x/net v0.30.0 // indirect
50-
golang.org/x/sync v0.8.0 // indirect
51-
golang.org/x/sys v0.26.0 // indirect
52-
golang.org/x/text v0.19.0 // indirect
53-
google.golang.org/protobuf v1.35.1 // indirect
54-
gopkg.in/yaml.v3 v3.0.1 // indirect
55-
sigs.k8s.io/yaml v1.4.0 // indirect
55+
github.com/ugorji/go/codec v1.3.1 // indirect
56+
golang.org/x/arch v0.26.0 // indirect
57+
golang.org/x/net v0.53.0 // indirect
58+
golang.org/x/sync v0.20.0 // indirect
59+
golang.org/x/sys v0.43.0 // indirect
60+
golang.org/x/text v0.36.0 // indirect
61+
google.golang.org/protobuf v1.36.11 // indirect
62+
sigs.k8s.io/yaml v1.6.0 // indirect
5663
)

0 commit comments

Comments
 (0)