Skip to content

Commit da96817

Browse files
authored
Merge pull request #4 from Gallegarmy/add-action
build: Add pipeline for auto-deploy images
2 parents a2cab88 + 18bd8eb commit da96817

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Upload Images to PostgreSQL (Docker)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- '**.png'
9+
- '**.jpg'
10+
- '**.jpeg'
11+
- '**.webp'
12+
13+
jobs:
14+
upload-images:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Get changed image files
22+
id: changed
23+
run: |
24+
FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '\.(png|jpg|jpeg|webp)$' || true)
25+
echo "files<<EOF" >> $GITHUB_OUTPUT
26+
echo "$FILES" >> $GITHUB_OUTPUT
27+
echo "EOF" >> $GITHUB_OUTPUT
28+
29+
- name: Setup SSH
30+
if: steps.changed.outputs.files != ''
31+
run: |
32+
mkdir -p ~/.ssh
33+
echo "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/id_rsa
34+
chmod 600 ~/.ssh/id_rsa
35+
ssh-keyscan -H 135.181.82.75 >> ~/.ssh/known_hosts
36+
37+
- name: Insert images into PostgreSQL (Docker)
38+
if: steps.changed.outputs.files != ''
39+
run: |
40+
IFS=$'\n'
41+
42+
{
43+
for file in ${{ steps.changed.outputs.files }}
44+
do
45+
filename= $(basename "$file" | sed 's/_/ /g')
46+
url="https://raw.githubusercontent.com/${{ github.repository }}/main/$file"
47+
48+
echo "INSERT INTO badges (name,description,image_url,is_permanent) VALUES ('$filename','$filename', '$url',true);"
49+
done
50+
} | ssh ${{ secrets.VPS_USER }}@135.181.82.75 \
51+
"docker exec -e PGPASSWORD=${{ secrets.DB_PASSWORD }} -i YOUR_CONTAINER_NAME \
52+
psql -U ${{ secrets.DB_USER }} -d ${{ secrets.DB_NAME }}"

0 commit comments

Comments
 (0)