Last active
April 9, 2020 12:52
-
-
Save MikeRogers0/01ab776069fad655cd23fa3215b0cbe1 to your computer and use it in GitHub Desktop.
Docker Setup for AWS Beanstalk
This file contains 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
.git | |
.gitignore | |
README.md | |
# | |
# OS X | |
# | |
.DS_Store | |
.AppleDouble | |
.LSOverride | |
# Icon must end with two \r | |
Icon | |
# Thumbnails | |
._* | |
# Files that might appear on external disk | |
.Spotlight-V100 | |
.Trashes | |
# Directories potentially created on remote AFP share | |
.AppleDB | |
.AppleDesktop | |
Network Trash Folder | |
Temporary Items | |
.apdisk | |
# | |
# Rails | |
# | |
.env.sample | |
*.rbc | |
capybara-*.html | |
log | |
tmp | |
db/*.sqlite3 | |
db/*.sqlite3-journal | |
public/system | |
public/assets | |
public/packs | |
public/packs-test | |
node_modules | |
yarn-error.log | |
yarn-debug.log* | |
.yarn-integrity | |
external_dns.log | |
coverage/ | |
spec/tmp | |
**.orig | |
.bundle | |
.ruby-gemset | |
.rvmrc | |
# if using bower-rails ignore default bower_components path bower.json files | |
vendor/assets/bower_components | |
*.bowerrc | |
bower.json |
This file contains 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
# .ebextensions/container_commands.config | |
container_commands: | |
01_migrate_db: | |
command: docker exec `docker ps -l -q -f 'status=running'` .heroku/release-tasks.sh RAILS_ENV=production | |
leader_only: true | |
ignoreErrors: false |
This file contains 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
# .github/workflows/beanstalk.yml | |
name: Deploy to AWS Beanstalk | |
on: | |
push: | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v1 | |
# This should be configured to push to AWS ECR | |
# But docker is easier for me to compare different environments. | |
- uses: whoan/docker-build-with-cache-action@v4 | |
with: | |
username: "${{ secrets.DOCKER_USERNAME }}" | |
password: "${{ secrets.DOCKER_PASSWORD }}" | |
image_name: mikerogers0/rails-timber-frame | |
image_tag: latest | |
build_extra_args: "--compress=true" | |
- name: Generate deployment package | |
run: zip deploy.zip Dockerrun.aws.json .ebextensions/container_commands.config | |
- name: Deploy to EB | |
uses: einaregilsson/beanstalk-deploy@v9 | |
with: | |
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
application_name: rails-timber-frame | |
environment_name: RailsTimberFrame-production | |
version_label: ${{ github.SHA }} | |
region: eu-west-1 | |
deployment_package: deploy.zip |
This file contains 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
wkhtml2pdf |
This file contains 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
--- | |
# Docker Compose 2.4 is for local development | |
# https://www.heroku.com/podcasts/codeish/57-discussing-docker-containers-and-kubernetes-with-a-docker-captain - Source on that. | |
version: '2.4' | |
services: | |
app: &app | |
container_name: RailsTimberFrame-App | |
image: rails-timber-frame:0.8.0 | |
build: | |
context: . | |
dockerfile: Dockerfile | |
env_file: | |
- .env | |
environment: | |
RAILS_LOG_TO_STDOUT: enabled | |
RAILS_SERVE_STATIC_FILES: enabled | |
NODE_ENV: development | |
RAILS_ENV: development | |
RACK_ENV: development | |
REDIS_URL: redis://@redis:6379/1 | |
DATABASE_URL: postgres://postgres:postgres@postgres:5432/ | |
BOOTSNAP_CACHE_DIR: /bundle/bootsnap | |
WEBPACKER_DEV_SERVER_HOST: webpacker | |
volumes: | |
- .:/usr/src/app | |
- rails_cache:/usr/src/app/tmp/cache | |
- bundle:/usr/local/bundle | |
- node_modules:/usr/src/app/node_modules | |
- packs:/usr/src/app/public/packs | |
depends_on: | |
postgres: | |
condition: service_healthy | |
redis: | |
condition: service_started | |
postgres: | |
container_name: RailsTimberFrame-Database | |
image: postgres:11.7-alpine | |
volumes: | |
- postgres:/var/lib/postgresql/data | |
ports: | |
- 5432 | |
environment: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
restart: on-failure | |
healthcheck: | |
test: ["CMD-SHELL", "pg_isready -U postgres"] | |
interval: 10s | |
timeout: 5s | |
retries: 5 | |
logging: | |
driver: none | |
redis: | |
container_name: RailsTimberFrame-Redis | |
image: redis:4.0.14-alpine | |
command: > | |
--save | |
--maxmemory 128mb | |
--maxmemory-policy noeviction | |
--stop-writes-on-bgsave-error yes | |
--rdbcompression yes | |
--rdbchecksum yes | |
--dir /data | |
volumes: | |
- redis:/data | |
ports: | |
- 6379 | |
restart: on-failure | |
healthcheck: | |
test: ["CMD", "redis-cli", "ping"] | |
interval: 10s | |
timeout: 5s | |
retries: 5 | |
logging: | |
driver: none | |
web: | |
<<: *app | |
container_name: RailsTimberFrame-Web | |
command: bash -c "rm -rf /usr/src/app/tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" | |
ports: | |
- "3000:3000" | |
worker: | |
<<: *app | |
container_name: RailsTimberFrame-Worker | |
command: bundle exec sidekiq -C config/sidekiq.yml | |
webpacker: | |
<<: *app | |
container_name: RailsTimberFrame-Webpacker | |
command: ./bin/webpack-dev-server | |
environment: | |
WEBPACKER_DEV_SERVER_HOST: 0.0.0.0 | |
ports: | |
- '3035:3035' | |
volumes: | |
postgres: | |
redis: | |
rails_cache: | |
bundle: | |
node_modules: | |
packs: |
This file contains 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
FROM ruby:2.6.5-slim AS development | |
LABEL maintainer="Mike Rogers <[email protected]>" | |
# Install the Essentials | |
RUN apt-get update -qq && apt-get install -y build-essential apt-transport-https ca-certificates gnupg2 netcat curl openssl tzdata | |
# Install the PostgreSQL packages | |
RUN apt-get install -y libpq-dev | |
# Install the nokogiri packages | |
RUN apt-get install -y libxml2-dev libxslt1-dev | |
# Add NodeJS to sources list | |
RUN curl -sL https://deb.nodesource.com/setup_13.x | bash - | |
# Install Yarn | |
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - | |
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list | |
RUN apt-get update -qq && apt-get install -y nodejs yarn | |
# Install bits for testing | |
RUN apt-get install -y libqtwebkit4 libqt4-dev xvfb chromium | |
# Add the current apps files into docker image | |
RUN mkdir -p /usr/src/app | |
WORKDIR /usr/src/app | |
# Install any extra dependencies via Aptfile | |
COPY Aptfile /usr/src/app/Aptfile | |
RUN apt-get install -y $(cat /usr/src/app/Aptfile | xargs) | |
ENV RAILS_LOG_TO_STDOUT enabled | |
ENV RAILS_SERVE_STATIC_FILES enabled | |
ENV PATH /usr/src/app/bin:$PATH | |
# Install latest bundler | |
RUN gem update --system && gem install bundler:2.0.2 | |
# Install Ruby Gems | |
COPY .ruby-version /usr/src/app | |
COPY Gemfile /usr/src/app | |
COPY Gemfile.lock /usr/src/app | |
RUN bundle check || bundle install --jobs=$(nproc) | |
# Copy the rest of the app | |
COPY . /usr/src/app | |
# Copy DB Sample | |
RUN cp -n /usr/src/app/config/database.yml.sample /usr/src/app/config/database.yml | |
# Clean up APT when done. | |
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | |
EXPOSE 3000 | |
CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3000"] | |
FROM development | |
# Install Yarn Libraries | |
RUN yarn install --check-files | |
# Compile the assets | |
RUN SECRET_KEY_BASE=secret-key-base RAILS_ENV=production RACK_ENV=production NODE_ENV=production bundle exec rake assets:precompile |
This file contains 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
{ | |
"AWSEBDockerrunVersion": 2, | |
"volumes": [], | |
"containerDefinitions": [ | |
{ | |
"command": [ | |
"bash", | |
"-c", | |
"rm -rf /usr/src/app/tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" | |
], | |
"memory": 256, | |
"environment": [], | |
"essential": true, | |
"image": "mikerogers0/rails-timber-frame:latest", | |
"mountPoints": [ | |
], | |
"name": "web", | |
"portMappings": [ | |
{ | |
"containerPort": 3000, | |
"hostPort": 80 | |
} | |
] | |
}, | |
{ | |
"command": [ | |
"bundle", | |
"exec", | |
"sidekiq", | |
"-C", | |
"config/sidekiq.yml" | |
], | |
"memory": 256, | |
"environment": [], | |
"essential": true, | |
"image": "mikerogers0/rails-timber-frame:latest", | |
"mountPoints": [ | |
], | |
"name": "worker" | |
} | |
], | |
"family": "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment