Skip to content

Example code for Ruby on Rails with AWS ECS.

License

Notifications You must be signed in to change notification settings

canhascodez/rails-on-ecs

 
 

Repository files navigation

test lint build License: MIT

日本語 | Jpanese

rails-on-ecs

Example code for Ruby on Rails with AWS ECS.

Terraform Repository: reireias/rails-on-ecs-terraform

Tips

Image builds

GitHub Actions are used to build images.

You can use docker/build-push-action to describe image build and push in a concise way.

The implementation uses multi-stage build like the implementation in Dockerfile.

In addition to the final image, the builder stage also pushes the ECR, which can be used as a cache for the next build by specifying the --cache-from option.

      # cache-from is the image of the previous builder stage
      - name: Build and Push
        uses: docker/build-push-action@v2
        env:
          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        with:
          push: true
          cache-from: |{ steps.login-ecr.outputs.registry }} with: push: true
            type=registry,ref=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:builder
          tags: |
            ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
            ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest

      # Save the builder image for this time
      - name: Save builder cache
        uses: docker/build-push-action@v2
        env:
          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        with:
          target: builder
          push: true
          build-args: |
            BUILDKIT_INLINE_CACHE=1
          tags: |{ env.
            ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:builder

health check

You can use the okcomputer gem to set up health checks in a simple way.

By accessing /health_checks/all, you can also perform health checks on additional specified DBs, etc. This is very useful for checking communication and investigating failures.

Load from environment variables

The following are read from environment variables to avoid tight coupling with specific infrastructure.

  • Database connection information: DATABASE_URL.
  • Database connection information (read replica): READER_DATABASE_URL.

Also, RAILS_MASTER_KEY is set as an environment variable for secure management of confidential information.

About

Example code for Ruby on Rails with AWS ECS.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 76.8%
  • HTML 17.2%
  • SCSS 2.9%
  • CSS 1.7%
  • Dockerfile 1.2%
  • JavaScript 0.2%