-
Notifications
You must be signed in to change notification settings - Fork 6
Setup Localstack AWS S3 for local development #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dcollie2
merged 13 commits into
main
from
118-set-up-local-azure-emulation-for-use-in-development
Jun 6, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6736b55
chore: add .env.example #118
hernanvicente c81e66a
dev: add tool-versions #118
hernanvicente b5f9043
chore: setup docker for development #118
hernanvicente 88518a6
chore: update database settings #118
hernanvicente 7f80490
chore: add localstack for aws
hernanvicente 6150622
dev: add make commands #118
hernanvicente 03ada97
dev: setup buckets #118
hernanvicente 916214f
chore: setup amazon provider for development #118
hernanvicente b02b8bd
test: config Rails and Capybara to run inside a container #118
hernanvicente 5f01aa7
dev: use local storage outside container
hernanvicente 6c68887
test: set RAILS_ENV for testing shell session
hernanvicente 4aaab52
doc: add docker's env vars url to Makefile
hernanvicente bea5129
Merge branch 'main' into 118-set-up-local-azure-emulation-for-use-in-…
dcollie2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "services": { | ||
| "s3": { | ||
| "buckets": [ | ||
| { | ||
| "name": "dev-bucket" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ruby 3.4.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Use Ruby 3.x with Alpine as base image for smaller size | ||
| FROM ruby:3.4.1-alpine | ||
|
|
||
| # Set environment variables for Rails | ||
| ENV RAILS_ENV=development \ | ||
| RACK_ENV=development \ | ||
| BUNDLE_PATH=/usr/local/bundle \ | ||
| BUNDLE_JOBS=4 \ | ||
| BUNDLE_RETRY=3 | ||
|
|
||
| # Install system dependencies and development tools | ||
| RUN apk add --no-cache \ | ||
| build-base \ | ||
| postgresql-dev \ | ||
| git \ | ||
| tzdata \ | ||
| bash \ | ||
| nss \ | ||
| freetype \ | ||
| freetype-dev \ | ||
| harfbuzz \ | ||
| ca-certificates \ | ||
| ttf-freefont \ | ||
| chromium \ | ||
| chromium-chromedriver | ||
|
|
||
| # Set Chrome environment variables | ||
| ENV CHROME_BIN=/usr/bin/chromium-browser \ | ||
| CHROME_PATH=/usr/lib/chromium/ | ||
|
|
||
| # Create and set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Install Ruby dependencies | ||
| COPY Gemfile Gemfile.lock ./ | ||
| RUN bundle install | ||
|
|
||
| # Add bind mount point for code | ||
| VOLUME /app | ||
|
|
||
| # Port used by Rails server | ||
| EXPOSE 3000 | ||
|
|
||
| # Configure entrypoint to run Rails | ||
| ENTRYPOINT ["./bin/docker-entrypoint.dev"] | ||
|
|
||
| # Start Rails server by default | ||
| CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # Project configuration | ||
|
|
||
| # Docker uses the directory environment variable to set a prefix for the service's container names. | ||
| # Doc: https://docs.docker.com/compose/how-tos/environment-variables/envvars/#compose_project_name | ||
| PROJECT_NAME := sk | ||
|
|
||
| # Colors for terminal output (optional) | ||
| BLUE := \033[34m | ||
| RESET := \033[0m | ||
|
|
||
| # Commands configuration | ||
| COMPOSE_CMD = COMPOSE_PROJECT_NAME=$(PROJECT_NAME) docker compose -f docker-compose.dev.yml | ||
| DOCKER_TEST_CMD = $(COMPOSE_CMD) exec app bundle exec rspec --format documentation | ||
| EXEC_CMD = $(COMPOSE_CMD) exec app | ||
|
|
||
| .PHONY: help build rebuild stop start restart logs shell console format test test_fast db_reset migrate clean clean_volumes | ||
|
|
||
| # Default target | ||
| help: | ||
| @echo "$(BLUE)Available commands:$(RESET)" | ||
| @echo " make build - Build image containers" | ||
| @echo " make rebuild - Clean, build, start containers and prepare database" | ||
| @echo " make stop [service] - Stop all containers or a specific service" | ||
| @echo " make start [service] - Start all containers or a specific service" | ||
| @echo " make restart [service] - Restart all containers or a specific service" | ||
| @echo " make logs [service] - View logs of all containers or a specific service" | ||
| @echo " make shell - Open a bash shell in the app container" | ||
| @echo " make console - Start Rails console" | ||
| @echo " make format - Auto-format code with Rubocop" | ||
| @echo " make test - Run all tests" | ||
| @echo " make test_fast - Run all tests and stop on first failure" | ||
| @echo " make migrate - Run database migrations" | ||
| @echo " make db_reset - Reset and rebuild database" | ||
| @echo " make clean - Remove all containers and volumes" | ||
| @echo " make clean_volumes - Remove all volumes" | ||
|
|
||
| build: | ||
| $(COMPOSE_CMD) build | ||
| @echo "✅ Build complete!" | ||
|
|
||
| rebuild: | ||
| @echo "🚀 Setting up..." | ||
| make clean | ||
| make build | ||
| make start | ||
| sleep 2 | ||
| $(EXEC_CMD) bundle exec rails db:reset | ||
| @echo "✅ Setup complete!" | ||
|
|
||
| stop: | ||
| $(COMPOSE_CMD) stop $(filter-out $@,$(MAKECMDGOALS)) | ||
|
|
||
| start: | ||
| $(COMPOSE_CMD) up -d $(filter-out $@,$(MAKECMDGOALS)) | ||
|
|
||
| restart: | ||
| $(COMPOSE_CMD) restart $(filter-out $@,$(MAKECMDGOALS)) | ||
|
|
||
| logs: | ||
| $(COMPOSE_CMD) logs -f $(filter-out $@,$(MAKECMDGOALS)) | ||
|
|
||
| shell: | ||
| $(EXEC_CMD) bash | ||
|
|
||
| console: | ||
| $(EXEC_CMD) bundle exec rails console | ||
|
|
||
| format: | ||
| $(EXEC_CMD) bundle exec rubocop --autocorrect-all | ||
|
|
||
| test: | ||
| export RAILS_ENV=test $(DOCKER_TEST_CMD) | ||
|
|
||
| test_fast: | ||
| $(DOCKER_TEST_CMD) --fail-fast | ||
|
|
||
| migrate: | ||
| $(EXEC_CMD) bundle exec rails db:migrate | ||
|
|
||
| db_reset: | ||
| $(EXEC_CMD) bundle exec rails db:drop db:create db:prepare | ||
|
|
||
| clean: | ||
| $(COMPOSE_CMD) down -v | ||
|
|
||
| clean_volumes: | ||
| docker volume rm -f $(PROJECT_NAME)_localstack_data $(PROJECT_NAME)_db_data | ||
|
|
||
| %: | ||
| @: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ Clone the codebase | |
| git clone [email protected]:rubyforgood/skillrx.git | ||
| ``` | ||
|
|
||
| Run the setup script to prepare DB and assets | ||
| Run the setup script to prepare the DB and assets | ||
| ```sh | ||
| bin/setup | ||
| ``` | ||
|
|
@@ -72,4 +72,95 @@ This project uses: | |
| * `shoulda-matchers` for expectations | ||
| * `factory_bot` for making records | ||
|
|
||
| To run tests simply use `bin/rspec`. You can also you `bin/quality` to check for code style issues. | ||
| To run tests, simply use `bin/rspec`. You can also use `bin/quality` to check for code style issues. | ||
|
|
||
| # Docker Development Environment | ||
|
|
||
| This project is containerised using Docker to ensure consistent development environments across the team. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Docker Engine installed on your system | ||
| - Docker Compose V2 or later | ||
|
|
||
| ## Initial Setup | ||
|
|
||
| 1. Copy the environment configuration file: | ||
| ``` | ||
| cp .env.example .env | ||
| ``` | ||
|
|
||
| 2. Configure the environment variables in `.env` as needed. These variables set up the containerised services. Update the `.env.example` file with any new or changed variables. | ||
|
|
||
| 3. To view the uploaded files from http://localstack:4566 in your browser, add the following line to your `/etc/hosts` to resolve `localstack` to your host system: | ||
| ``` | ||
| 127.0.0.1 localstack | ||
| ``` | ||
|
|
||
| 4. Build and start the containers: | ||
| ``` | ||
| docker compose up | ||
| ``` | ||
|
|
||
| This will build the images and initialise the containers. You can exit and stop the containers using CTRL+C. | ||
|
|
||
| ## Container Architecture | ||
| The development environment consists of three containerised services: | ||
|
|
||
| * app : Rails application service | ||
| * Handles the main application logic | ||
| * Runs on Ruby on Rails | ||
| * db : PostgreSQL database service | ||
| * Persists application data | ||
| * Runs independently from the application | ||
| * localstack : AWS S3 emulator | ||
| * Provides local S3-compatible storage | ||
| * Enables development without actual AWS setup | ||
|
|
||
| ## Development Workflow | ||
|
|
||
| We provide a Makefile to simplify common development tasks. Here are the most frequently used commands: | ||
| ``` | ||
| make build # Build image containers | ||
| make start [service] # Start all containers or a specific service | ||
| make stop [service] # Stop all containers or a specific service | ||
| make shell # Open a bash shell in the app container | ||
| make console # Start Rails console | ||
| make test # Run all tests | ||
| ``` | ||
|
|
||
| For a complete list of available commands: | ||
| ```bash | ||
| make help | ||
| ``` | ||
|
|
||
| ## Common Tasks | ||
| ### Rebuilding the Environment | ||
| To completely rebuild your development environment: | ||
|
|
||
| ```bash | ||
| make rebuild | ||
| ``` | ||
| This command will clean existing containers, rebuild images, and prepare the database. | ||
|
|
||
| ### Viewing Logs | ||
| To monitor service logs: | ||
| ``` | ||
| make logs # View all container logs | ||
| make logs app # View only Rails application logs | ||
| ``` | ||
|
|
||
| ### Container Management | ||
| Individual services can be managed using: | ||
| ``` | ||
| make start db # Start only the database container | ||
| make stop app # Stop only the application container | ||
| make restart db # Restart only the database container | ||
| ``` | ||
|
|
||
| ### Troubleshooting | ||
| If you encounter issues: | ||
| - Ensure all required ports are available on your system | ||
| - Verify that your .env file contains all necessary variables | ||
| - Try rebuilding the environment with make rebuild | ||
| - Check container logs for specific error messages | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/bin/bash -e | ||
|
|
||
| # Remove any existing server.pid file | ||
| rm -f /app/tmp/pids/server.pid | ||
|
|
||
| # Install new gems if any | ||
| bundle check || bundle install | ||
|
|
||
| # If running the rails server then create or migrate existing database | ||
| ./bin/rails db:prepare | ||
|
|
||
| # Execute the main command passed to docker run | ||
| exec "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.