Skip to content
Merged

Dev #258

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions .github/workflows/prod-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,8 @@ on:
jobs:
deploy:
name: Deploy to Prod
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
runs-on: self-hosted
#concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- name: Execute remote SSH commands using password
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd /home/deploy/source-be
git checkout main
git pull
./build.sh
sudo /bin/systemctl restart source-be
- name: Execute deploy script
run: cd ~/Developer/source-be-deploy && ./deploy.sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ resources/admins_encrypted.json

.db
admins.json
admins_encrypted.json
prod.env
33 changes: 33 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

cd ~/Developer/source-be-deploy

echo "Pulling changes..."
git pull

echo "Starting compilation..."
clojure -T:build uber

echo "Creating archive..."
mkdir source-be-deploy
cp start.sh migrate.sh source-be.service deps.edn target/source-be-standalone.jar source-be-deploy
cp -r resources src source-be-deploy
cp prod.env source-be-deploy/.env
tar -czvf source-be-deploy.tar.gz ./source-be-deploy

echo "Copying archive..."
sshpass -e scp -r ~/Developer/source-be-deploy/source-be-deploy.tar.gz deploy@api.wearesource.earth:/home/deploy
echo "Done!"

echo "Setting up prod server..."
sshpass -e ssh deploy@api.wearesource.earth "
echo "Extracting archive..."
tar -xvzf source-be-deploy.tar.gz

echo "Restarting service..."
sudo systemctl restart source-fe.service
"

echo "Cleaning up..."
rm -rf source-be-deploy
rm source-be-deploy.tar.gz
19 changes: 19 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

echo "Installing service..."
chmod +x deploy.sh
chmod +x install_runner.sh
chmod +x migrate.sh

./deploy.sh

sshpass -e ssh deploy@api.wearesource.earth "
cd /home/deploy/source-be-deploy
chmod +x start.sh
chmod +x migrate.sh

sudo mv source-be.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable source-be.service
sudo systemctl start source-be.service
"
10 changes: 10 additions & 0 deletions install_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

mkdir -p ~/.config/source-be/actions-runner
cd ~/.config/source-be/actions-runner

curl -o actions-runner-linux-x64-2.334.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.334.0/actions-runner-linux-x64-2.334.0.tar.gz

tar xzf ./actions-runner-linux-x64-2.334.0.tar.gz

./config.sh --url https://github.com/modulr-software/source-be --token AMFR4ML2O5TLDW2O5JR6KCTJ7H7U2
1 change: 1 addition & 0 deletions migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

export $(grep '.*' .env | xargs)

echo "Running migrations..."
clojure -M:migrate "$@"
1 change: 0 additions & 1 deletion resources/admins_encrypted.json

This file was deleted.

10 changes: 5 additions & 5 deletions resources/staging_config.edn → resources/config.edn
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{:supersecretkey #env SUPER_SECRET_KEY
:admins-path "resources/admins.json"
:admins-encrypted-path "resources/admins_encrypted.json"
:cors-origin #or [#env CORS_ORIGIN "https://mervstation.tail4f070.ts.net"]
:base-url #or [#env BASE_URL "https://mervstation.tail4f070.ts.net/sourcebe"]
:port #or [#env PORT 3998]
:env #or [#env ENV "staging"]
:cors-origin #or [#env CORS_ORIGIN "https://localhost:4000"]
:base-url #or [#env BASE_URL "http://localhost:3000"]
:port #or [#env PORT 3000]
:env #or [#env ENV "prod"]
:database {:url #or [#env DATABASE_URL "postgres://localhost"]
:type "postgresql"}
:email {:address #or [#env SUPPORT_ADDRESS "lee@wearesource.earth"]
:username #env EMAIL_USERNAME
:password #env EMAIL_PASSWORD}
:oauth2 {:google {:authorization-uri "https://accounts.google.com/o/oauth2/auth"
:access-token-uri "https://oauth2.googleapis.com/token"
:redirect-uri #or [#env GOOGLE_REDIRECT_URI "https://mervstation.tail4f070.ts.net/sourcebe/oauth2/google/callback"]
:redirect-uri #or [#env GOOGLE_REDIRECT_URI "https://api.wearesource.earth/oauth2/google/callback"]
:client-id #env GOOGLE_CLIENT_ID
:client-secret #env GOOGLE_CLIENT_SECRET
:access-query-param :access_token
Expand Down
22 changes: 0 additions & 22 deletions resources/dev_config.edn

This file was deleted.

4 changes: 4 additions & 0 deletions runner_config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@



Y
12 changes: 12 additions & 0 deletions source-be.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Source Back End Server Startup Service
After=postgresql.service

[Service]
Type=simple
ExecStart=/home/deploy/source-be-deploy/start.sh
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
4 changes: 1 addition & 3 deletions src/source/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
[:oauth2 [:map-of keyword? oauth2-provider-schema]]])

(defn- load-config []
(let [environment (get (System/getenv) "ENV")
environment (if (nil? environment) "dev" environment)
config (aero/read-config (io/resource (str environment "_config.edn")))
(let [config (aero/read-config (io/resource "config.edn"))
decoded (m/decode schema config mt/string-transformer)]
(when-not (m/validate schema decoded)
(println (->> decoded
Expand Down
9 changes: 5 additions & 4 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash

cd /home/deploy/source-be-deploy
export $(grep '.*' .env | xargs)

echo "Running migrations before startup..."
clojure -M:migrate
./migrate.sh up

echo "Starting server..."
$JAVA_CMD -jar target/source-be-standalone.jar
echo "Starting backend server..."
/home/deploy/.jenv/shims/java -jar source-be-standalone.jar
43 changes: 0 additions & 43 deletions test/source_be/cache_test.clj

This file was deleted.

59 changes: 0 additions & 59 deletions test/source_be/google_test.clj

This file was deleted.

Loading