-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (161 loc) · 5.76 KB
/
docker.yaml
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Build and Push Docker Image
on:
push:
branches:
- main
workflow_dispatch:
inputs:
environment:
description: "Environment to deploy to"
required: true
default: "production"
type: choice
options:
- production
- staging
- development
debug_enabled:
description: "Run the deployment with debug logging"
required: false
type: boolean
default: false
jobs:
rust-checks:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Rust Cache
uses: Swatinem/[email protected]
with:
cache-all-crates: true
shared-key: rust-cache
cache-on-failure: true
- name: Setup Rust
run: rustup toolchain install stable --profile minimal --no-self-update
- name: Check formatting
run: cargo fmt --all -- --check
- name: Build
run: cargo build
- name: Run Clippy
run: cargo clippy -- -D warnings
docker-build:
needs: rust-checks
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Downcase REPO
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=sha,format=short
labels: |
org.opencontainers.image.title=luuma
org.opencontainers.image.description=Anime picture fetcher bot
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
maintainer=towinok
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
- name: Verify Docker image
if: success()
run: |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker image inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
# deploy:
# needs: docker-build
# runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write
# env:
# REGISTRY: ghcr.io
# CONTAINER_NAME: lum
# steps:
# - name: Downcase REPO
# run: |
# echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
# - name: Check secrets
# run: |
# if [ -z "${{ secrets.SERVER_IP }}" ]; then
# echo "SERVER_IP is missing"
# exit 1
# fi
# if [ -z "${{ secrets.SERVER_USERNAME }}" ]; then
# echo "SERVER_USERNAME is missing"
# exit 1
# fi
# if [ -z "${{ secrets.SERVER_PASSWORD }}" ]; then
# echo "SERVER_PASSWORD is missing"
# exit 1
# fi
# echo "All required secrets are present"
# - name: Deploy to Server
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.SERVER_IP }}
# username: ${{ secrets.SERVER_USERNAME }}
# password: ${{ secrets.SERVER_PASSWORD }}
# port: 22
# debug: true
# timeout: 30s
# script: |
# # Логин в GitHub Container Registry
# echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# # Проверка и остановка существующего контейнера
# if docker ps -a | grep -q "${{ env.CONTAINER_NAME }}"; then
# echo "Stopping and removing existing container..."
# docker stop ${{ env.CONTAINER_NAME }}
# docker rm ${{ env.CONTAINER_NAME }}
# else
# echo "No existing container found"
# fi
# # Проверка и удаление существующего образа
# if docker image ls | grep -q "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"; then
# echo "Removing existing image..."
# docker image rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
# else
# echo "No existing image found"
# fi
# # Загрузка нового образа
# echo "Pulling new image..."
# docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
# # Запуск нового контейнера
# echo "Starting new container..."
# docker run -d \
# --name ${{ env.CONTAINER_NAME }} \
# --restart unless-stopped \
# -e DS_TOKEN=${{ secrets.DS_TOKEN }} \
# ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
# # Очистка неиспользуемых образов
# echo "Cleaning up unused images..."
# docker image prune -f
# # Выход из registry
# docker logout ${{ env.REGISTRY }}