A service that resizes and uploads images to S3.
This an image processing service that resizes and uploads images to AWS S3.
This service allows a user to register for an account using their email address, user name ad a profile picture. The picture is then optionally resized and uploaded to amazon s3. To use it:
- Register for an account by submitting your details using the register route.
- You can update your details using the update route.
This application has several features including:
- Deployed to an AWS EBS.
- Versioned using git and Hosted on GitHub.
- Auto-deployed to AWS EBS using Github actions.
- Uses gunicorn as the application servers.
- Uses an Application Load Balancer to redirect traffic to the frontend
- Uses AWS S3 to store the image.
Here is how to set up the application locally:
-
Clone the application repo:
git clone https://github.com/twyle/image-processing-service.git
-
Navigate into the cloned repo:
cd image-processing-service
-
Create a Virtual environment:
python3 -m venv venv
-
Activate the virtual environmnet:
source venv/bin/activate
-
Install the project dependancies:
pip install --upgrade pip # update the package manager pip install -r requirements.txt
-
Create the environment variables for each service:
touch .env
Then paste the following into the file:
FLASK_APP=manage.py FLASK_DEBUG=True FLASK_ENV=development S3_BUCKET=flask-image-service AWS_ACCESS_KEY=<AWS_ACCESS_KEY> AWS_ACCESS_SECRET=<AWS_ACCESS_SECRET> POSTGRES_HOST=db POSTGRES_USER=lyle POSTGRES_PASSWORD=lyle POSTGRES_DB=image-service POSTGRES_PORT=5432 CELERY_RESULT_BACKEND=redis://redis:6379/0 CELERY_BROKER_URL=redis://redis:6379/0
-
Start the services:
docker-compose -f docker-compose-dev.yml up --build
-
Create the database:
docker-compose -f docker-compose-dev.yml exec image-service python manage.py create_db
-
View the running application
Head over to http://0.0.0.0:5000/apidocs
-
Services
The application consists of one service that send account activation emails to users:
- Email Service
This service is resposible for sending account activation emails. The routes include:
Route Method Description 'api/v1/auth/register' POST Register a new user 'api/v1/user/ POST Update a new user - Just enter user details and select an image and it will be uploaded.
This service uses AWS S3 to store the images.
-
Coding standards
The application had to adhere to the following coding standards:
- Variable names
- Function names
- Test driven development
- Individual modules need 60% coverage and an overall coverage of 60%.
- CI/CD pipeline has to pass before deployments.
- Commit messages format has to be adhered to.
- Only push code to github using development branches.
- Releases have to be tagged.
- Use pre-commit to run code quality checks
- Use comitizen to format commit messages
-
Application development process management
The project uses GitHub Projects for management.
The application uses atleast 5 branches:
- Features branch used to develop new features.
- Development branch used to hold the most upto date features that are yet to be deployed.
- Staging branch holds the code that is currently being tested for production.
- The release branch holds all the assets used when creating a release.
- The production branch holds the code for the currently deployed application.
The development workflow follows the following steps:
- A feature branch is created for the development of a new feature.
- The code is then pushed to GitHub, triggering the feature-development-workflow.yml workflow. If all the tests pass, the feature is reviewde and merged into the development branch.
- The code in the development branch is then deployed to the development environment. If the deployment is succesful, the development branch is merged into the staging branch.
- This triggers the staging workflow. If all the tests are succesful, this branch is reviewed and deployed to a staging environment.
- For creatinga release, the staging branch is merged into the release branch. This happens when a tag is pushed to GitHub.
- Once a release is created, the release branch is merged into the production branch, which is deployed into production.
The workflows require a couple of secrets to work:
```sh
FLASK_APP=manage.py
FLASK_DEBUG=True
FLASK_ENV=development
S3_BUCKET=flask-image-service
AWS_ACCESS_KEY=<AWS_ACCESS_KEY>
AWS_ACCESS_SECRET=<AWS_ACCESS_SECRET>
POSTGRES_HOST=db
POSTGRES_USER=lyle
POSTGRES_PASSWORD=lyle
POSTGRES_DB=image-service
POSTGRES_PORT=5432
CELERY_RESULT_BACKEND=redis://redis:6379/0
CELERY_BROKER_URL=redis://redis:6379/0
```
The workflows also require the followingenvironments to work:
- Test
- Staging
- Development
- Production
And within each environment, create a secret that indicates the environment type i.e
- Test ->
FLASK_ENV=test
- Staging ->
FLASK_ENV=stage
- Development ->
FLASK_ENV=development
- Production ->
FLASK_ENV=production
- Fork it https://github.com/twyle/email-service/fork
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
Lyle Okoth – @lylethedesigner on twitter
lyle okoth on medium
My email is [email protected]
Here is my GitHub Profile
You can also find me on LinkedIN
Distributed under the MIT license. See LICENSE
for more information.