-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (63 loc) · 2.11 KB
/
Copy pathci-cd.yml
File metadata and controls
77 lines (63 loc) · 2.11 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
name: CI
on:
push:
branches: ["main"]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build and push the Docker image to GHCR
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: Dockerfile
push: true
tags: ghcr.io/harsche/game-collection-api:latest
- name: List built images
run: docker images
deploy:
needs: build
runs-on: ubuntu-latest
environment: oracle-vm
permissions:
contents: read
steps:
- name: Deploy to Oracle VM
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.ORACLE_VM_HOST }}
username: ${{ secrets.ORACLE_VM_USERNAME }}
key: ${{ secrets.ORACLE_VM_SSH_KEY }}
script: |
GH_ACTOR="${{ github.actor }}"
# Log in to GitHub Container Registry
echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u "$GH_ACTOR" --password-stdin
# Pull the latest image
docker pull ghcr.io/harsche/game-collection-api:latest
# Stop and remove the old container if it exists
docker stop game-collection-api || true
docker rm game-collection-api || true
# Run the new container
docker run -d \
--name game-collection-api \
-p 8080:8080 \
-e ASPNETCORE_ENVIRONMENT=Production \
-e "Jwt__Key=${{ secrets.JWT_SECRET_KEY }}" \
-e "DefaultAdminPassword=${{ secrets.DEFAULT_ADMIN_PASSWORD }}" \
ghcr.io/harsche/game-collection-api:latest