Skip to content

Commit 66aff1e

Browse files
authored
Merge pull request #401 from DefangLabs/codex/fix-bug-in-important-code-section
Fix variable typo in nodejs-react-postgres server
0 parents  commit 66aff1e

File tree

133 files changed

+2962
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+2962
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG RUBY_VERSION=3.3.4
2+
FROM ghcr.io/rails/devcontainer/images/ruby:$RUBY_VERSION
3+
4+
RUN apt-get update -qq \
5+
&& apt-get install -y postgresql-client libpq-dev \
6+
&& apt-get clean \
7+
&& rm -rf /var/lib/apt/lists/*

.devcontainer/devcontainer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": "."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
9+
},
10+
"runArgs": [
11+
"--env-file", ".env"
12+
],
13+
"appPort": 3000,
14+
"forwardPorts": [],
15+
"customizations": {
16+
"vscode": {
17+
"settings": {
18+
"remote.autoForwardPorts": false
19+
}
20+
}
21+
}
22+
}

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SECRET_KEY_BASE=example
2+
POSTGRES_USERNAME=postgres
3+
POSTGRES_HOST=db

.github/workflows/deploy.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
environment: playground
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout Repo
18+
uses: actions/checkout@v4
19+
20+
- name: Deploy
21+
uses: DefangLabs/[email protected]
22+
with:
23+
config-env-vars: POSTGRES_PASSWORD
24+
env:
25+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Ruby on Rails
2+
3+
[![1-click-deploy](https://raw.githubusercontent.com/DefangLabs/defang-assets/main/Logos/Buttons/SVG/deploy-with-defang.svg)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-rails-template%26template_owner%3DDefangSamples)
4+
5+
This template is a member list project developed using Ruby on Rails, offering a starting point to help you quickly build your team management system. We have prepared all the essential files for deployment. By spending less than 10 minutes setting up the environment, as detailed in the prerequisites, and executing the commands in our step-by-step guide, your website will be ready to go live to the world!
6+
7+
## Essential Setup Files
8+
9+
1. A [Dockerfile](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/) to describe the basic image of your applications.
10+
2. A [docker-compose file](https://docs.defang.io/docs/concepts/compose) to define and run multi-container Docker applications.
11+
3. A [.dockerignore](https://docs.docker.com/build/building/context/#dockerignore-files) file to comply with the size limit (10MB).
12+
13+
## Development Using [Dev Containers](https://containers.dev/)
14+
15+
1. Open the working directory with Visual Studio Code or any editor which supports Dev Containers.
16+
2. Click on the bottom left corner of the window where you see "Reopen in Container".
17+
3. Open up a shell in the VS Code terminal and run `docker compose -f compose.dev.yaml up --build`.
18+
19+
20+
## Configuration
21+
22+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration). Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
23+
24+
### `POSTGRES_PASSWORD`
25+
This password will be used to initialize the PostgreSQL database and to connect to it.
26+
27+
28+
## Deployment
29+
30+
> [!NOTE]
31+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
32+
33+
### Defang Playground
34+
35+
Deploy your application to the defang playground by opening up your terminal and typing `defang up`.
36+
37+
### BYOC (AWS)
38+
39+
If you want to deploy to your own cloud account, you can use Defang BYOC:
40+
41+
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
42+
2. Run `defang --provider=aws up` in a terminal that has access to your AWS environment variables.
43+
44+
---
45+
46+
Title: Ruby on Rails
47+
48+
Short Description: A basic member list project developed using Ruby on Rails.
49+
50+
Tags: Ruby, Rails
51+
52+
Languages: Ruby

app/.dockerignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
2+
3+
# Ignore git directory.
4+
/.git/
5+
6+
# Ignore bundler config.
7+
/.bundle
8+
9+
# Ignore all environment files (except templates).
10+
/.env*
11+
!/.env*.erb
12+
13+
# Ignore all default key files.
14+
/config/master.key
15+
/config/credentials/*.key
16+
17+
# Ignore all logfiles and tempfiles.
18+
/log/*
19+
/tmp/*
20+
!/log/.keep
21+
!/tmp/.keep
22+
23+
# Ignore pidfiles, but keep the directory.
24+
/tmp/pids/*
25+
!/tmp/pids/.keep
26+
27+
# Ignore storage (uploaded files in development and any SQLite databases).
28+
/storage/*
29+
!/storage/.keep
30+
/tmp/storage/*
31+
!/tmp/storage/.keep
32+
33+
# Ignore assets.
34+
/node_modules/
35+
/app/assets/builds/*
36+
!/app/assets/builds/.keep
37+
/public/assets
38+
39+
/test

app/.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See https://git-scm.com/docs/gitattributes for more about git attribute files.
2+
3+
# Mark the database schema as having been generated.
4+
db/schema.rb linguist-generated
5+
6+
# Mark any vendored files as having been vendored.
7+
vendor/* linguist-vendored
8+
config/credentials/*.yml.enc diff=rails_credentials
9+
config/credentials.yml.enc diff=rails_credentials

app/.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2+
#
3+
# If you find yourself ignoring temporary files generated by your text editor
4+
# or operating system, you probably want to add a global ignore instead:
5+
# git config --global core.excludesfile '~/.gitignore_global'
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore all environment files (except templates).
11+
/.env*
12+
!/.env*.erb
13+
14+
# Ignore all logfiles and tempfiles.
15+
/log/*
16+
/tmp/*
17+
!/log/.keep
18+
!/tmp/.keep
19+
20+
# Ignore pidfiles, but keep the directory.
21+
/tmp/pids/*
22+
!/tmp/pids/
23+
!/tmp/pids/.keep
24+
25+
# Ignore storage (uploaded files in development and any SQLite databases).
26+
/storage/*
27+
!/storage/.keep
28+
/tmp/storage/*
29+
!/tmp/storage/
30+
!/tmp/storage/.keep
31+
32+
/public/assets
33+
34+
# Ignore master key for decrypting credentials and more.
35+
/config/master.key

app/.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby-3.3.4

app/Dockerfile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# syntax = docker/dockerfile:1
2+
3+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
4+
ARG RUBY_VERSION=3.3.4
5+
FROM ruby:$RUBY_VERSION-slim as base
6+
7+
# Rails app lives here
8+
WORKDIR /rails
9+
10+
# Set production environment
11+
ENV RAILS_ENV="production" \
12+
BUNDLE_DEPLOYMENT="1" \
13+
BUNDLE_PATH="/usr/local/bundle" \
14+
BUNDLE_WITHOUT="development"
15+
16+
# Throw-away build stage to reduce size of final image
17+
FROM base as build
18+
19+
# Install packages needed to build gems
20+
RUN apt-get update -qq \
21+
&& apt-get install --no-install-recommends -y build-essential git libvips pkg-config libpq-dev \
22+
&& apt-get clean \
23+
&& rm -rf /var/lib/apt/lists/*
24+
25+
# Set bundler config to force ruby platform
26+
RUN bundle config set force_ruby_platform true
27+
28+
# Install application gems
29+
COPY Gemfile Gemfile.lock ./
30+
RUN bundle install && \
31+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git \
32+
&& bundle exec bootsnap precompile --gemfile
33+
34+
# Copy application code
35+
COPY . .
36+
37+
# Precompile bootsnap code for faster boot times
38+
RUN bundle exec bootsnap precompile app/ lib/
39+
40+
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
41+
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
42+
43+
44+
# Final stage for app image
45+
FROM base
46+
47+
# Install packages needed for deployment
48+
RUN apt-get update -qq \
49+
&& apt-get install --no-install-recommends -y curl libvips libpq-dev \
50+
&& apt-get clean \
51+
&& rm -rf /var/lib/apt/lists/*
52+
53+
# Copy built artifacts: gems, application
54+
COPY --from=build /usr/local/bundle /usr/local/bundle
55+
COPY --from=build /rails /rails
56+
57+
# Run and own only the runtime files as a non-root user for security
58+
RUN useradd rails --create-home --shell /bin/bash \
59+
&& chown -R rails:rails db log storage tmp
60+
USER rails:rails
61+
62+
# Entrypoint prepares the database.
63+
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
64+
65+
# Start the server by default, this can be overwritten at runtime
66+
EXPOSE 3000
67+
CMD ["./bin/rails", "server"]

0 commit comments

Comments
 (0)