Skip to content

Commit fdd18d4

Browse files
committed
improved deploy process / CDN support
1 parent 1d95319 commit fdd18d4

File tree

6 files changed

+77
-6
lines changed

6 files changed

+77
-6
lines changed

.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
REACT_APP_API_URL=http://localhost:8000
1+
REACT_APP_API_URL=http://localhost:8000
2+
3+
PUBLIC_URL=https://sdn-host.net/public/
4+
5+
CDN_HOST=some-ftp-host.com
6+
CDN_LOGIN=gitcom
7+
CDN_PASSWORD=your-password

scripts/deploy/prod/copy_build.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

scripts/deploy/prod/deploy.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/bash
2-
rm -rf /usr/local/gitcom/frontend/app/build/*
3-
cp -avr /usr/local/gitcom/frontend/app/tmp/build /usr/local/gitcom/frontend/app/
2+
python3 scripts/deploy/prod/stages/cdn_upload.py
3+
./scripts/deploy/prod/stages/copy_build.sh $1
4+
ssh $1 "bash -s" < ./scripts/deploy/prod/stages/deploy.sh
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os.path, os
2+
from ftplib import FTP, error_perm
3+
4+
from dotenv import load_dotenv
5+
load_dotenv()
6+
7+
load_dotenv(verbose=True)
8+
9+
from pathlib import Path
10+
env_path = Path('.') / '.env'
11+
12+
host = os.getenv("CDN_HOST")
13+
port = 21
14+
15+
ftp = FTP()
16+
ftp.connect(host,port)
17+
ftp.login(os.getenv("CDN_LOGIN"), os.getenv("CDN_PASSWORD"))
18+
19+
def count_files(path):
20+
files_count = 0
21+
for name in os.listdir(path):
22+
localpath = os.path.join(path, name)
23+
if os.path.isfile(localpath):
24+
files_count += 1
25+
elif os.path.isdir(localpath):
26+
files_count += 1
27+
files_count += count_files(localpath)
28+
return files_count
29+
30+
def upload_folder(ftp, path, prefix = None):
31+
if prefix is not None:
32+
progress = 0
33+
print("total files: " + str(count_files(path)) + " in " + path)
34+
root_dir = "/gitcom/" + prefix
35+
try:
36+
ftp.mkd(root_dir)
37+
except error_perm as e:
38+
print(e)
39+
ftp.cwd(root_dir)
40+
41+
for name in os.listdir(path):
42+
localpath = os.path.join(path, name)
43+
if os.path.isfile(localpath):
44+
print("Storing ", name, localpath)
45+
ftp.storbinary('STOR ' + name, open(localpath,'rb'))
46+
elif os.path.isdir(localpath):
47+
print("MKD", name)
48+
49+
try:
50+
ftp.mkd(name)
51+
except error_perm as e:
52+
print(e)
53+
54+
print("CWD", name)
55+
ftp.cwd(name)
56+
upload_folder(ftp, localpath)
57+
print("CWD", "..")
58+
ftp.cwd("..")
59+
60+
upload_folder(ftp, "build", "public/")
61+
62+
ftp.quit()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
scp -r build "$1":/usr/local/gitcom/frontend/app/tmp
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
rm -rf /usr/local/gitcom/frontend/app/build/*
3+
cp -avr /usr/local/gitcom/frontend/app/tmp/build /usr/local/gitcom/frontend/app/

0 commit comments

Comments
 (0)