-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (79 loc) · 2.6 KB
/
Contribution.GitLab.VPS.yaml
File metadata and controls
95 lines (79 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: GitLab Contribution API - VPS
on:
workflow_dispatch:
push:
branches: [ master, main ]
paths:
- 'src/Contribution.Common/**'
- 'src/Contribution.GitLab/**'
- 'deploy/Dockerfile.c-gl-api'
- '.github/workflows/Contribution.GitLab.VPS.yaml'
env:
SERVICE_NAME: backend-gitlab
IMAGE: ghcr.io/${{ github.repository_owner }}/contribution-gitlab-api
DOCKERFILE: deploy/Dockerfile.c-gl-api
DOTNET_VERSION: '9.0.x'
permissions:
contents: read
packages: write
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU (multiarch)
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ${{ env.DOCKERFILE }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Deploy to VPS
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
set -e
echo "Deploying GitLab API service..."
# Login to GHCR
echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# Navigate to app directory
cd /srv/app || exit 1
# Pull latest images
docker compose pull ${{ env.SERVICE_NAME }}
# Restart the service
docker compose up -d ${{ env.SERVICE_NAME }}
# Clean up old images
docker image prune -f
echo "GitLab API service deployed successfully!"