Repository navigation
66 lines (54 loc) · 1.93 KB
/
Copy pathdeploy.yml
File metadata and controls
66 lines (54 loc) · 1.93 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
name: Build and Deploy
on:
push:
branches:
- main
env:
DOCKER_IMAGE: ${{ secrets.DOCKER_USERNAME }}/ecobot
CONTAINER_NAME: ecobot-app
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.DOCKER_IMAGE }}:latest
${{ env.DOCKER_IMAGE }}:${{ github.sha }}
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache,mode=max
- name: Deploy to server
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SERVER_PORT || 22 }}
script: |
docker pull ${{ env.DOCKER_IMAGE }}:latest
# Create logs directory and ensure it's writable
mkdir -p /opt/ecobot/logs
chown -R 1000:1000 /opt/ecobot/logs
docker stop ${{ env.CONTAINER_NAME }} || true
docker rm ${{ env.CONTAINER_NAME }} || true
docker run -d \
--name ${{ env.CONTAINER_NAME }} \
--restart unless-stopped \
--network host \
--env-file /opt/ecobot/.env \
-e LOG_PATH=/var/log/ecobot/ecobot.log \
-v /opt/ecobot/logs:/var/log/ecobot \
${{ env.DOCKER_IMAGE }}:latest
docker image prune -af --filter "until=48h"