diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml new file mode 100644 index 000000000..412de8650 --- /dev/null +++ b/.github/workflows/production.yml @@ -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"'" + }' diff --git a/app/src/build.prod.js b/app/src/build.prod.js new file mode 100644 index 000000000..d4d9c0e87 --- /dev/null +++ b/app/src/build.prod.js @@ -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; diff --git a/backend/rtmis-cron b/backend/rtmis-cron index a1f8e922c..bf04de829 100644 --- a/backend/rtmis-cron +++ b/backend/rtmis-cron @@ -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 \ No newline at end of file +01 23 * * * date >> /app/cron.log && cd /app/ && bash -l ./job.sh >> /app/cron.log 2>&1 + diff --git a/backend/seeder.prod.sh b/backend/seeder.prod.sh new file mode 100755 index 000000000..34c31b3ac --- /dev/null +++ b/backend/seeder.prod.sh @@ -0,0 +1,71 @@ +#!/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 Fake User? [y/n]" +read -r fake_user +if [[ "${fake_user}" == 'y' || "${fake_user}" == 'Y' ]]; then + echo "Creating User for Admin with email admin@akvo.org" + python manage.py createsuperuser \ + --email admin@akvo.org --first_name Admin --last_name One + python manage.py assign_access admin@akvo.org --admin + # python manage.py fake_user_seeder --repeat 50 +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 Fake Data? [y/n]" +read -r seed_fake_data +if [[ "${seed_fake_data}" == 'y' || "${seed_fake_data}" == 'Y' ]]; then + python manage.py fake_data_seeder +fi + +echo "Seed Fake Data Claim? [y/n]" +read -r seed_fake_data_claim +if [[ "${seed_fake_data_claim}" == 'y' || "${seed_fake_data_claim}" == 'Y' ]]; then + python manage.py fake_data_claim_seeder +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 diff --git a/deploy/docker-compose.frontend-build.yml b/deploy/docker-compose.frontend-build.yml index 1d64528be..b24b46da5 100644 --- a/deploy/docker-compose.frontend-build.yml +++ b/deploy/docker-compose.frontend-build.yml @@ -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