Skip to content

Commit

Permalink
Merge pull request akvo#1535 from akvo/feature/1533-self-host
Browse files Browse the repository at this point in the history
Fix seeder + CI
  • Loading branch information
ifirmawan authored Jul 16, 2024
2 parents 541aa1c + 7f74da3 commit b93b86a
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 1 deletion.
97 changes: 97 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: RTMIS Build and Deploy Prod

on:
push:
branches:
- main

jobs:
build_and_deploy_jobs:
name: RTMIS Build and Deploy Jobs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set short git commit SHA
id: vars
run: |
shortSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$shortSha" >> $GITHUB_ENV
- name: Docker compose rebuild
uses: ./.github/composite-actions/ssh-docker-compose
with:
server-ip: ${{ secrets.SERVER_IP }}
server-ssh-port: ${{ secrets.SERVER_SSH_PORT }}
server-ssh-secret-key: ${{ secrets.SERVER_SSH_SECRET_KEY }}
server-ssh-user: ${{ secrets.SERVER_SSH_USER }}
docker-compose-file: ${{ secrets.DOCKER_COMPOSE_FILE }}
docker-compose-file-frontend-build: ${{ secrets.DOCKER_COMPOSE_FILE_FRONTEND_BUILD }}
ci_commit: ${{ env.COMMIT_SHORT_SHA }}

mobile-app-release:
name: Mobile App Build
needs: build_and_deploy_jobs
runs-on: ubuntu-latest
steps:
- name: 🗄️ Checkout repository
uses: actions/checkout@v3

- name: 🧰 Setup node
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: 🏗 Setup EAS
uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}

- name: 📦 Install dependencies
run: |
cd ./app/
cp ./src/build.prod.js ./src/build.js
npm install
- name: 🚀 Release to Expo Dev
id: eas_release
working-directory: ./app
run: |
npm run eas:release > output.txt
cat output.txt
echo "APK_URL=$(tail -n 1 output.txt)" >> $GITHUB_ENV
- name: Set short git commit SHA
id: vars
run: |
shortSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$shortSha" >> $GITHUB_ENV
- name: Get App Version
id: get_version
run: |
cd app
apk_version=$(grep '"version":' package.json | sed -E 's/.*"version": *"([^"]+)".*/\1/')
echo "APK_VERSION=$apk_version" >> $GITHUB_ENV
- name: 🌟 Send APK
env:
APK_VERSION: ${{ env.APK_VERSION }}
SECRET: ${{ secrets.APK_UPLOAD_SECRET }}
SENTRY_ENV: production
SENTRY_DSN: ${{ secrets.SENTRY_MOBILE_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_MOBILE_AUTH_TOKEN }}
run: |
curl -X 'POST' \
'https://rtmis.akvo.org/api/v1/device/apk/upload' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"apk_url": "'"$APK_URL"'",
"apk_version": "'"$APK_VERSION"'",
"secret": "'"$SECRET"'"
}'
9 changes: 9 additions & 0 deletions app/src/build.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import buildJson from './build.json';

const defaultBuildParams = {
...buildJson,
serverURL: 'https://rtmis.akvo.org/api/v1/device',
apkURL: 'https://rtmis.akvo.org/app',
};

export default defaultBuildParams;
3 changes: 2 additions & 1 deletion backend/rtmis-cron
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
00 23 * * * cat /proc/1/environ | tr '\0' '\n' > /etc/environment
01 23 * * * date >> /app/cron.log && cd /app/ && bash -l ./job.sh >> /app/cron.log 2>&1
01 23 * * * date >> /app/cron.log && cd /app/ && bash -l ./job.sh >> /app/cron.log 2>&1

49 changes: 49 additions & 0 deletions backend/seeder.prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

echo "Seed Administration? [y/n]"
read -r seed_administration
if [[ "${seed_administration}" == 'y' || "${seed_administration}" == 'Y' ]]; then
python manage.py administration_seeder
python manage.py resetsequence v1_profile
fi

echo "Add New Super Admin? [y/n]"
read -r add_account
if [[ "${add_account}" == 'y' || "${add_account}" == 'Y' ]]; then
echo "Please type email address"
read -r email_address
if [[ "${email_address}" != '' ]]; then
python manage.py createsuperuser --email "${email_address}"
python manage.py assign_access "${email_address}"
fi
fi

echo "Seed Form? [y/n]"
read -r seed_form
if [[ "${seed_form}" == 'y' || "${seed_form}" == 'Y' ]]; then
python manage.py form_seeder
python manage.py generate_config
fi

echo "Seed Organisation? [y/n]"
read -r seed_organization
if [[ "${seed_organization}" == 'y' || "${seed_organization}" == 'Y' ]]; then
python manage.py organisation_seeder
fi

echo "Seed Entities? [y/n]"
read -r seed_entities
if [[ "${seed_entities}" == 'y' || "${seed_entities}" == 'Y' ]]; then
python manage.py entities_seeder
fi

echo "Seed Administration Attribute? [y/n]"
read -r seed_administration_attribute
if [[ "${seed_administration_attribute}" == 'y' || "${seed_administration_attribute}" == 'Y' ]]; then
python manage.py administration_attribute_seeder
fi

python manage.py generate_sqlite

# python manage.py fake_approver_seeder
# python manage.py fake_data_seeder
2 changes: 2 additions & 0 deletions deploy/docker-compose.frontend-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
image: akvo/akvo-node-17-alpine:20220121.024749.f30b815
container_name: frontend_build
working_dir: /app
environment:
- CI_COMMIT=${CI_COMMIT}
command:
- /bin/bash
- -c
Expand Down

0 comments on commit b93b86a

Please sign in to comment.