Skip to content

Commit

Permalink
Sample app working docker deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Nov 17, 2024
1 parent 2e7243a commit b35771b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
3 changes: 1 addition & 2 deletions sample-app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY=<value from config/master.key> my-app

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
ARG RUBY_VERSION=3.3.4
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
FROM docker.io/library/ruby:3.3.4-slim AS base

# Rails app lives here
WORKDIR /rails
Expand Down
4 changes: 2 additions & 2 deletions sample-app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ source "https://rubygems.org"

# Our gems
gem 'aws-sdk-rails',
path: '../'
# git: 'https://github.com/aws/aws-sdk-rails'
# path: '../'
git: 'https://github.com/aws/aws-sdk-rails', branch: '4.2'

gem 'aws-actiondispatch-dynamodb', git: 'https://github.com/aws/aws-actiondispatch-dynamodb-ruby'
gem 'aws-actionmailbox-ses', git: 'https://github.com/aws/aws-actionmailbox-ses-ruby'
Expand Down
43 changes: 26 additions & 17 deletions sample-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,25 @@ packages:
git: []
```
Rails and AWS environment variables were added to the Dockerfile.
## Pre-requisite: Deploying an Elastic Beanstalk Web Server and Worker
Some of the features require a web server and worker with Elastic Beanstalk. To deploy the sample app to Elastic Beanstalk, follow these steps:
Create a EB application with a **web server environment** using the Ruby platform. Use the default settings (including using the default/sample app initially) except:
Create a EB application with a **web server environment** using the **Ruby platform**.
Use the default settings (including using the default/sample app initially) except:
1. (Optional) Set an EC2 key pair.
2. Choose the default VPC and enable all of the subnets. Enable a public IP address.
3. Set the root volume to General Purpose 3.
4. Select a bigger instance than the micro default, such as m7.large.
5. Set `SECRET_KEY_BASE` to `SECRET` in the environment configuration.
6. Set `AWS_REGION` to your region in the environment configuration.

In SQS, create an queue called `active-job-worker`.
In SQS, create two queues called `active-job-worker` and `active-job-worker-docker`.

Create a EB application with a **worker environment** using the Ruby platform. Use the default settings (including using the default/sample app initially) except:
Create a EB application with a **worker environment** using the **Ruby platform**.
Use the default settings (including using the default/sample app initially) except:
1. (Optional) Set an EC2 key pair.
2. Choose the default VPC and enable all of the subnets. Enable a public IP address.
3. Set the root volume to General Purpose 3.
Expand All @@ -52,12 +56,21 @@ Create a EB application with a **worker environment** using the Ruby platform. U
7. Set `SECRET_KEY_BASE` to `SECRET` in the environment configuration.
8. Set `AWS_REGION` to your region in the environment configuration.

Create a EB application with a **worker environment** using the **Docker platform**.
Use the default settings (including using the default/sample app initially) except:
1. (Optional) Set an EC2 key pair.
2. Choose the default VPC and enable all of the subnets. Enable a public IP address.
3. Set the root volume to General Purpose 3.
4. Select a bigger instance than the micro default, such as m7.large.
5. Set the worker queue to your personal `active-job-worker-docker` queue.

Navigate to IAM and for the new role (`aws-elasticbeanstalk-ec2-role`) add the `AmazonDynamoDBFullAccess` policy.

After initial deployment of the sample app and worker:
1. Run `rm Gemfile.lock && bundle install && bundle lock --add-platform ruby`
2. Create a zip of the sample-app: `zip ../sample-app.zip -r * .[^.]*`.
3. Upload the zip file to your EB web environments.
After initial deployment of the sample app and workers:
1. Ensure `path` is not used in the Gemfile - GitHub and branch may be used.
2. Run `rm Gemfile.lock && bundle install && bundle lock --add-platform ruby`
3. Create a zip of the sample-app: `zip ../sample-app.zip -r * .[^.]*`.
4. Upload the zip file to your EB web environments.

You can find web logs under `/var/log/puma/puma.log`

Expand Down Expand Up @@ -255,18 +268,14 @@ Visit `http://127.0.0.1:3000/queue_sqs_job` and `http://127.0.0.1:3000/queue_sqs

Run the sample-app locally with `AWS_ACTIVE_JOB_QUEUE_URL=https://my_sqs_queue_url rails console`.

Send a test job: `TestJob.perform_later('elastic beanstalk worker test')`
Send a test job: `TestJob.perform_later('elastic beanstalk worker test')`.

You can then request the logs and should see processing of the job in `/var/log/puma/puma.log`
You can then request the logs and should see processing of the job in `/var/log/puma/puma.log`.

### Testing with Docker Elastic Beanstalk workers
For Docker workers, the logs are in `/var/log/eb-docker/containers/eb-current-app/eb-<container>-stdouterr.log` .

# TODO - this does not work generally
Repeat this for either the worker or docker worker queues.

* Build the sample app with docker: `docker build -t sample-app-docker`
* Install the [eb cli](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html#eb-cli3-install.scripts).
* Ensure docker is running.
* Create a docker application using `eb create` and then create a worker environment using `eb create -t worker -it t3.large`. Note: this will create a new SQS queue.
* Update local sqs active job config to use the new queue and submit a test job: `rails c` and then `TestJob.perform_later(hello: 'from ebs')`
### Testing with Lambda

> **Note**: The dockerfile must set `AWS_REGION="us-west-2"` and `AWS_PROCESS_BEANSTALK_WORKER_REQUESTS="true"` and `SECRET_KEY_BASE="SECRET"`.
TODO

0 comments on commit b35771b

Please sign in to comment.