anitab-forms-backend icon indicating copy to clipboard operation
anitab-forms-backend copied to clipboard

[Feat]: Add heroku configuration for deployment

Open Rahulm2310 opened this issue 3 years ago • 30 comments

Description

Add heroku configuration for deployment Fixes #80

Instructions for deployment :

  1. Login to Heroku
    heroku login
    
  2. After you have executed the command ‘heroku login’, in the web browser, you are now redirected to the page as shown in the image below. Here, you are required to click on the ‘Log In’ button.
  3. Now, you are required to create an app in Heroku. Hence, for the stated purpose you are required to execute the following command.
    heroku create open-source-programs-backend
    
  4. After the successful execution of the command you can now view your application in Heroku devcenter.
  5. For deploying your application you are required to execute the following command.
    git push heroku develop
    
  6. To commit initial migration on the Heroku application you are required to execute the following query.
    heroku run python manage.py migrate
    
  7. Finally, you can execute the following command to view the hosted website.
    heroku open
    

Type of Change:

  • Code
  • Outreach

Code/Quality Assurance Only

  • New feature (non-breaking change which adds functionality pre-approved by mentors)

How Has This Been Tested?

Not Applicable

Checklist:

  • [x] My PR follows the style guidelines of this project
  • [x] I have performed a self-review of my own code or materials

Code/Quality Assurance Only

  • [x] My changes generate no new warnings

Rahulm2310 avatar Feb 27 '21 17:02 Rahulm2310

@codesankalp @isabelcosta Can you please review this PR. Thanks 🙂

Rahulm2310 avatar Feb 27 '21 17:02 Rahulm2310

@Rahulm2310 Will this be able to deploy from the Heroku pipeline through github?

QA checks are also failing.

codesankalp avatar Feb 28 '21 06:02 codesankalp

@Rahulm2310 Follow the README guidelines for QA-Checks as both workflows are failing.

codesankalp avatar Mar 02 '21 05:03 codesankalp

@codesankalp Can you please explain why both workflows are still failing?

Rahulm2310 avatar Mar 02 '21 20:03 Rahulm2310

@Rahulm2310 Try to follow the commands mentioned in README - https://github.com/anitab-org/open-source-programs-backend#qa-checks You can also check the suggestion of the workflow. When QA-Checks will pass I will review this PR.

codesankalp avatar Mar 04 '21 18:03 codesankalp

For testing, you can use gunicorn main.wsgi.

codesankalp avatar Mar 07 '21 15:03 codesankalp

I tried it on the local system and it is returning 500 server errors for URL which is working.

I think that is may be because you don't have DJANGO_DEBUG in your .env file. Also, I am getting this when running gunicorn main.wsgi. image

Rahulm2310 avatar Mar 08 '21 15:03 Rahulm2310

@Rahulm2310 I have DJANGO_DEBUG in my .env file. DJANGO_DEBUG=False will be used in production which only means any error will not be shown on the deployed backend. And I am not sure why gunicorn main.wsgi returns an error in windows because I tried it on Ubuntu. You can research about this error. But what I wanted is that after running this command it must not show any errors (Server error 500).

codesankalp avatar Mar 08 '21 16:03 codesankalp

@codesankalp I came to know that gunicorn is for unix environment and is incompatible with windows. There is an open issue on the gunicorn's github repo for this.

Rahulm2310 avatar Mar 08 '21 17:03 Rahulm2310

Then @Rahulm2310 there is only one option try deploying on Heroku for testing your code.

codesankalp avatar Mar 08 '21 17:03 codesankalp

@codesankalp is this the correct way DEBUG = os.environ.get("DJANGO_DEBUG", "") != "False" ? Also, this works if I remove DJANGO_DEBUG from .env file.

Rahulm2310 avatar Mar 08 '21 17:03 Rahulm2310

@Rahulm2310 The line that you have added is correct i.e. it will make DEBUG=False when DJANGO_DEBUG=False will be present in .env file else it will make DEBUG=True in any other remaining condition.

codesankalp avatar Mar 08 '21 18:03 codesankalp

@codesankalp I tried deploying to heroku. But getting this error when running heroku run python manage.py migrate. image. image

Although, I have download file in the project's root still shows this.

Rahulm2310 avatar Mar 08 '21 18:03 Rahulm2310

Try to rebase it with the current develop branch then there will be no errors regarding Zulip Key. The download file is in your local directory but as it is also present in .gitignore because of this it is not present in heroku.

codesankalp avatar Mar 09 '21 05:03 codesankalp

@codesankalp I rebased with current develop, pushed the download file to heroku and then heroku run python manage.py migrate ran successfully. Here's the deployed link https://open-source-programs-backend.herokuapp.com/api. Could you please check and confirm if it looks alright so that I can push the changes here.

Rahulm2310 avatar Mar 09 '21 08:03 Rahulm2310

image I tried making a user and it returns a server error. Maybe you need to set up all environment variables (including sendgrid email) in the .env file.

codesankalp avatar Mar 09 '21 08:03 codesankalp

Maybe you need to set up all environment variables (including sendgrid email) in the .env file.

I tried adding SENDGRID_API_KEY to heroku config vars(environment variables), still showing the same error. Also, when I tried it locally it gives me this error image Although, my from address is verified sender identity on sendgrid, still getting this error.

Rahulm2310 avatar Mar 11 '21 18:03 Rahulm2310

Maybe you need to set up all environment variables (including sendgrid email) in the .env file.

I tried adding SENDGRID_API_KEY to heroku config vars(environment variables), still showing the same error. Also, when I tried it locally it gives me this error image Although, my from address is verified sender identity on sendgrid, still getting this error.

Is it working on local and not working on heroku?

codesankalp avatar Mar 12 '21 13:03 codesankalp

@codesankalp getting server error when registering a user on heroku.

This is the error when registering a user on local. image

Rahulm2310 avatar Mar 12 '21 17:03 Rahulm2310

@Rahulm2310 See this for reference: https://sendgrid.com/docs/ui/sending-email/sender-verification/

codesankalp avatar Mar 12 '21 17:03 codesankalp

@codesankalp I have my sender email verified on sendgrid. osp-sendgrid

Can I add you as a collaborator to the deployed project on heroku.

Rahulm2310 avatar Mar 13 '21 18:03 Rahulm2310

No, It is not needed @Rahulm2310. If it's a problem related to SendGrid then I will suggest using another email service or consoleBackend. Let me know if it was able to solve the problem. Also, Can you access the admin site and was able to create a user from there?

codesankalp avatar Mar 13 '21 18:03 codesankalp

If it's a problem related to SendGrid then I will suggest using another email service or consoleBackend.

@codesankalp I tried consoleBackend, and I am getting the verification mail in the console. osp-console Seems that this is a problem related to sendgrid.

Also, Can you access the admin site and was able to create a user from there?

yeah I created a super user for heroku app and then created a new user from the admin site. image

Rahulm2310 avatar Mar 15 '21 17:03 Rahulm2310

@Rahulm2310 In that case I can approve this PR. I will review it again soon.

codesankalp avatar Mar 15 '21 17:03 codesankalp

@Rahulm2310 Can you please resolve the merge conflict and do the suggested changes?

codesankalp avatar Apr 03 '21 16:04 codesankalp

@codesankalp was a bit more involved in OSH. Will apply the suggested changes asap. 🙂

Rahulm2310 avatar Apr 03 '21 20:04 Rahulm2310

Hi, @Rahulm2310 can you do the changes in this, as the deployment of the backend, is one of the high priority things for us currently.

Aaishpra avatar Apr 17 '21 14:04 Aaishpra

@Rahulm2310 It is a priority now because the deployed backend is required. Can you please update the PR?

codesankalp avatar Apr 22 '21 18:04 codesankalp

@codesankalp can you help me identify why CI builds are failing

Rahulm2310 avatar Apr 24 '21 08:04 Rahulm2310

@codesankalp can you help me identify why CI builds are failing

Not sure, It is something related to postgres. I think while deleting the database it can't delete it. I will research about it more.

codesankalp avatar Apr 24 '21 17:04 codesankalp