hackgvl / events-api

API for Greenville Tech Calendar events
MIT License
11 stars 6 forks source link

Add Docker Support #43

Closed oliviasculley closed 2 years ago

oliviasculley commented 2 years ago

Summary

This PR adds the necessary files to build the upstate-tech-cal-service container and host it using Docker Compose. I've also added some documentation, so please let me know if you have any thoughts or issues with this branch!

Issues

Closes #41

allella commented 2 years ago

I cloned this PR and Docker pulls the images, but then I started getting errors related to _loggingconfig.ini. I noticed logging_config.ini was a directory and I don't think I made that mistake, so I'm wondering if Docker is creating a logging_config.ini directory when there should be a file there?

I deleted the logging_config.ini and copied the logging_config.ini.example to logging_config.ini and it gives a new error, which is also related to a directory

Also, the deploy_notes_docker.md in section 3.1 says to copy a file that doesn't exist, so perhaps that's the problem

cp logging_config.ini.example-docker logging_config.ini

ERROR: for upstate-tech-cal-server Cannot start service upstate-tech-cal-server: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\"/home/username/public_html/upstate_tech_cal_service/logging_config.ini\\" to rootfs \\"/var/lib/docker/overlay2/b2792e2f70f5eb350830478b0c0dc500c48182adf2f3d70af3fe7c7f62c159c5/merged\\" at \\"/var/lib/docker/overlay2/b2792e2f70f5eb350830478b0c0dc500c48182adf2f3d70af3fe7c7f62c159c5/merged/app/logging_config.ini\\" caused \\"not a directory\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type ERROR: Encountered errors while bringing up the project.

oliviasculley commented 2 years ago

Sorry about that, since the logging works as usual you should just use the regular logging_config.ini.example. You're correct that docker will attempt to create the folder for you if it still exists, but that bind mount error is a bit weird. Could you try running docker-compose down and docker-compose rm -v to get rid of the bind mounts and recreate them?

allella commented 2 years ago

Alright. I think it got further and then a new error

image

The directory was there and I got this message. I deleted the directory and ran docker-compose up again and the directory was recreated. It seems the Docker script is creating an _allmeetings.json directory, but _allmeetings.json is typically the file that's written by the Python script.

image

allella commented 2 years ago

I'm going to guess the docker-compose.yml needs a tweak in the volumes section, but I'll await your input.

volumes:
  - "./config.ini:/app/config.ini"
  - "./logging_config.ini:/app/logging_config.ini"
  - "./all_meetings.json:/app/all_meetings.json"
oliviasculley commented 2 years ago

Sorry, you'll need to run touch all_meetings.json before starting the container, otherwise it'll get recreated as a directory. I'll add it to the instructions sometime today :+1:

allella commented 2 years ago

Alright, it's working now.

I'm getting an application error, which I think is from me updating packages while debugging things on the other open PR. If it's rendering the API results for you without error, then I'll go ahead and merge this in since it shouldn't break the app anyway.

Then, once I get Ramona's PR merged in we'll probably want to look at updating the Python modules and documenting that process for Conda because it's been years since it was fresh in my mind and I've been struggling and just guessing at the best commands to have Conda properly install new modules and update the environment.

upstate-tech-cal-server    |   File "/opt/conda/envs/cal_service/lib/python3.6/site-packages/flask/json.py", line 251, in jsonify
upstate-tech-cal-server    |     if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr:
upstate-tech-cal-server    | AttributeError: 'Request' object has no attribute 'is_xhr'
ramonaspence commented 2 years ago

Alright, it's working now.

I'm getting an application error, which I think is from me updating packages while debugging things on the other open PR. If it's rendering the API results for you without error, then I'll go ahead and merge this in since it shouldn't break the app anyway.

Then, once I get Ramona's PR merged in we'll probably want to look at updating the Python modules and documenting that process for Conda because it's been years since it was fresh in my mind and I've been struggling and just guessing at the best commands to have Conda properly install new modules and update the environment.

upstate-tech-cal-server    |   File "/opt/conda/envs/cal_service/lib/python3.6/site-packages/flask/json.py", line 251, in jsonify
upstate-tech-cal-server    |     if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr:
upstate-tech-cal-server    | AttributeError: 'Request' object has no attribute 'is_xhr'

This error will go away with the other PR. Flask by default uses its own jsonify rather than the default python module. The version of Flask that this repo is using (is very old) is trying to access a method request.is_xhr that Werkzeug deprecated.

There's a couple of options for this: For a temporary fix, we can add the line app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False Otherwise, we just need to update Flask OR pin Werkzeug to a specific version in the environment.yml.

The last fix would be to not use Flask's JSONIFY, and in my PR, I've removed the use of Flask's JSONIFY and replaced it with Python's default json module.

I'm sure we should update Flask anyways, but I thought I'd jump in and explain that error.

Edit: I meant to add this link to the github issue for this in Flask

allella commented 2 years ago

Thanks. I did find that Werkzeug was part of the issue, but I was confused why it started happening on the live site on an old 2020 commit that was working fine.

I thought it was because I restarted Gunicorn, but I think it was because I ran something outside of Conda, likepip update, or something in a frenzy to fix other errors.

ramonaspence commented 2 years ago

I just happened to run into the same error earlier :)

allella commented 2 years ago

Alright. Both PRs have been merged in and are pulled to the live server.

Kudos.