Skip to content

Commit

Permalink
Tested and working
Browse files Browse the repository at this point in the history
  • Loading branch information
ineshbose committed Feb 26, 2022
1 parent 5d8e395 commit a94db86
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 9 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/deploy-app.yml
@@ -0,0 +1,80 @@
name: Deploy App

on:
push:
paths:
- "src/*"
branches:
- develop
defaults:
run:
working-directory: src

jobs:
deploy-app:
name: Deploy app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: expo/expo-github-action@v7
with:
expo-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- name: Install modules
run: yarn install
- name: Write environment data
run: |
echo "${{ secrets.ENV_DATA }}" > .env
mkdir env
echo "" > env/index.ts
- name: Generate env/index.ts
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const dotenv = require('dotenv');
const env = dotenv.parse(fs.readFileSync('${{ github.workspace }}/src/.env', 'utf-8'));
fs.writeFileSync(
'${{ github.workspace }}/src/env/index.ts',
`export const {${Object.keys(env).join(', ')}} = ${JSON.stringify(env)};`
);
- name: Build web client
run: |
sed -i "0,/path: '\/'/s//path: '\/portion-mate'/" app/navigation/LinkingConfiguration.ts
expo build:web
- name: Write README
run: echo "## Deployed React App (FOR DEMO ONLY)" >> ./web-build/README.md
- name: Deploy react app
uses: JamesIves/github-pages-deploy-action@v4.2.5
with:
branch: gh-pages
folder: src/web-build
- name: Env file
run: |
echo "!server/.env" >> .gitignore
cp .env server/.env
sed -i '0,/..\/.env/s//.env/' server/server/settings.py
cp pyproject.toml server/pyproject.toml
echo "." >> server/requirements.txt
echo "gunicorn" >> server/requirements.txt
echo "whitenoise" >> server/requirements.txt
echo "django-heroku" >> server/requirements.txt
echo "dj-database-url" >> server/requirements.txt
echo "import django_heroku" >> server/server/settings.py
echo "django_heroku.settings(locals())" >> server/server/settings.py
echo "import dj_database_url" >> server/server/settings.py
echo "DATABASES[\"default\"] = dj_database_url.config(conn_max_age=600, ssl_require=True)" >> server/server/settings.py
sed -i '0,/# \"whitenoise/s//\"whitenoise/' server/server/settings.py
sed -i '0,/# STATICFILES_STORAGE/s//STATICFILES_STORAGE/' server/server/settings.py
cp manage.py server/manage.py
sed -i '0,/sys.path.append("server")/s//#/' server/manage.py
echo "web: gunicorn server.wsgi" >> server/Procfile
echo "release: python manage.py migrate" >> server/Procfile
- name: Deploy django server
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
heroku_email: ${{ secrets.HEROKU_EMAIL }}
appdir: "src/server"
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -9,6 +9,7 @@
<!-- BADGES / SHIELDS -->

<p align="center">
<a href="https://inesh.xyz/portion-mate" target="_blank"><img alt="GitHub deployments" src="https://img.shields.io/github/deployments/ineshbose/portion-mate/github-pages?style=flat-square"></a>
<a href="https://app.codacy.com/gh/ineshbose/portion-mate/dashboard" target="_blank"><img alt="Codacy grade" src="https://img.shields.io/codacy/grade/57b01d85bcfa4d8bb96978e1edb2edff?style=flat-square&logo=codacy&logoColor=white"></a>
<a href="https://codeclimate.com/github/ineshbose/portion-mate" target="_blank"><img alt="Code Climate maintainability" src="https://img.shields.io/codeclimate/maintainability/ineshbose/portion-mate?style=flat-square&logo=codeclimate&logoColor=white"></a>
<a href="https://portion-mate.readthedocs.io/" target="_blank"><img alt="Read the Docs" src="https://img.shields.io/readthedocs/portion-mate?style=flat-square&logo=readthedocs&logoColor=white"></a>
Expand Down Expand Up @@ -66,7 +67,7 @@ Portion Mate is an application that helps keep track of your food intake. This p

_For more information, please refer to the [Wiki](https://github.com/ineshbose/portion-mate/wiki)._

## 🗺 Project Layout
## 🗺 Project Layout

- [`.`](/#) Root of repository with directories of different concerns
- [`package.json`](/package.json) is the repository module handler using [Yarn Workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces/) and [lint-staged](https://github.com/okonet/lint-staged)
Expand Down
2 changes: 1 addition & 1 deletion src/.gitignore
Expand Up @@ -401,4 +401,4 @@ Network Trash Folder
Temporary Items
.apdisk

# End of https://www.toptal.com/developers/gitignore/api/django,reactnative
# End of https://www.toptal.com/developers/gitignore/api/django,reactnative
4 changes: 2 additions & 2 deletions src/app.json
@@ -1,11 +1,11 @@
{
"expo": {
"name": "portion-mate",
"slug": "pmfrontend",
"slug": "portion-mate",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./app/assets/images/icon.png",
"scheme": "myapp",
"scheme": "pmate",
"userInterfaceStyle": "automatic",
"splash": {
"image": "./app/assets/images/splash.png",
Expand Down
5 changes: 3 additions & 2 deletions src/app/navigation/LinkingConfiguration.ts
Expand Up @@ -5,15 +5,16 @@
*/

import { LinkingOptions } from '@react-navigation/native';
import { makeUrl } from 'expo-linking';
import { createURL } from 'expo-linking';

import { RootStackParamList } from '../types/navigation';

const linking: LinkingOptions<RootStackParamList> = {
prefixes: [makeUrl('/')],
prefixes: [createURL('/')],
config: {
screens: {
Root: {
path: '/',
screens: {
BottomTab: {
screens: {
Expand Down
1 change: 1 addition & 0 deletions src/package.json
Expand Up @@ -2,6 +2,7 @@
"name": "portion-mate-src",
"version": "1.0.0",
"main": "index.js",
"homepage": "http://ineshbose.github.io/portion-mate",
"scripts": {
"start": "expo start",
"android": "expo start --android",
Expand Down
14 changes: 11 additions & 3 deletions src/server/server/settings.py
Expand Up @@ -26,9 +26,14 @@

ALLOWED_HOSTS = env("ALLOWED_HOSTS", default=["http://127.0.0.1"])

CORS_ALLOWED_ORIGINS = [
"http://localhost:19006",
]
CORS_ALLOWED_ORIGINS = (
[
"http://localhost:19006",
]
+ [host for host in ALLOWED_HOSTS if host.startswith("http")]
+ [f"http://{host}" for host in ALLOWED_HOSTS if not host.startswith("http")]
+ [f"https://{host}" for host in ALLOWED_HOSTS if not host.startswith("http")]
)

# Application definition

Expand All @@ -55,6 +60,7 @@
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
# "whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
Expand Down Expand Up @@ -143,6 +149,8 @@

MEDIA_ROOT = Path.joinpath(BASE_DIR, "media/")

# STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"


# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
Expand Down

0 comments on commit a94db86

Please sign in to comment.