-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The only changes needed to get this working in k8s + Tilt
- Loading branch information
1 parent
7890f58
commit 5ca0c05
Showing
7 changed files
with
138 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# syntax = docker/dockerfile:1 | ||
|
||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile | ||
ARG RUBY_VERSION=3.3.0 | ||
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base | ||
|
||
# Rails app lives here | ||
WORKDIR /rails | ||
|
||
# Set development environment | ||
ENV RAILS_ENV="development" \ | ||
BUNDLE_PATH="/usr/local/bundle" | ||
|
||
# Install packages needed to build gems and node modules | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y build-essential curl git libpq-dev libvips node-gyp pkg-config python-is-python3 | ||
|
||
# Install JavaScript dependencies | ||
ARG NODE_VERSION=20.10.0 | ||
ARG YARN_VERSION=1.22.19 | ||
ENV PATH=/usr/local/node/bin:$PATH | ||
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \ | ||
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \ | ||
npm install -g yarn@$YARN_VERSION && \ | ||
rm -rf /tmp/node-build-master | ||
|
||
# Install application gems | ||
COPY Gemfile Gemfile.lock ./ | ||
RUN bundle install | ||
|
||
# Install node modules | ||
COPY package.json yarn.lock ./ | ||
RUN yarn install | ||
|
||
# Copy application code | ||
COPY . . | ||
|
||
# Build assets in dev mode | ||
RUN yarn build | ||
RUN yarn build:css | ||
|
||
# Entrypoint prepares the database. | ||
ENTRYPOINT ["/rails/bin/docker-entrypoint"] | ||
|
||
# Start the server by default, this can be overwritten at runtime | ||
EXPOSE 3000 | ||
CMD ["./bin/rails", "server"] |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
load('ext://helm_resource', 'helm_resource', 'helm_repo') | ||
load('ext://podman', 'podman_build') | ||
load('ext://secret', 'secret_from_dict') | ||
load('ext://uibutton', 'cmd_button') | ||
|
||
# Set up secrets with defaults for development | ||
k8s_yaml(secret_from_dict('tiltfile', inputs = { | ||
'postgres-password' : os.getenv('POSTGRESQL_PASSWORD', 's3sam3') | ||
})) | ||
|
||
# Use Helm to spin up postgres | ||
helm_resource( | ||
name='postgresql', | ||
chart='oci://registry-1.docker.io/bitnamicharts/postgresql', | ||
flags=[ | ||
# TODO: 15.x appears to have problems with ephemeral-storage limits that | ||
# I haven't been able to debug yet | ||
'--version=^14.0', | ||
'--set=image.tag=16.2.0-debian-12-r8', | ||
'--set=global.postgresql.auth.existingSecret=tiltfile' | ||
], | ||
labels=['database'] | ||
) | ||
|
||
# The Rails app itself is built and served by app.yaml | ||
podman_build('rails-example', '.', | ||
extra_flags=['--file', 'Containerfile.dev'], | ||
live_update=[ | ||
fall_back_on(['./config']), | ||
sync('.', '/rails'), | ||
run('bundle', trigger=['./Gemfile', './Gemfile.lock']), | ||
run('yarn', trigger=['./package.json', './yarn.lock']), | ||
run('yarn build', trigger=['./app/javascript']), | ||
run('yarn build:css', trigger=['./app/assets/stylesheets']), | ||
] | ||
) | ||
k8s_yaml('k8s.yaml') | ||
k8s_resource('rails-example', | ||
labels=['app'], | ||
resource_deps=['postgresql'], | ||
port_forwards='3000:3000' | ||
) | ||
cmd_button('rails-example:db-migrate', | ||
argv=['./bin/tilt-run', 'rails', 'db:migrate'], | ||
resource='rails-example', | ||
icon_name='engineering', | ||
text='Run migrations', | ||
) | ||
cmd_button('rails-example:db-reset', | ||
argv=['./bin/tilt-run', 'rails', 'db:seed:replant'], | ||
resource='rails-example', | ||
icon_name='restart_alt', | ||
text='Reset database', | ||
requires_confirmation=True, | ||
) |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
RESOURCE=rails-example | ||
POD_NAME="$(tilt get kubernetesdiscovery "$RESOURCE" -ojsonpath='{.status.pods[0].name}')" | ||
# If we're running this from a terminal, attach a terminal here too | ||
if [ -t 0 ]; then FLAGS="-ti"; fi | ||
kubectl exec $FLAGS "$POD_NAME" -- bundle exec $@ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: rails-example | ||
labels: | ||
app: rails-example | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: rails-example | ||
template: | ||
metadata: | ||
labels: | ||
app: rails-example | ||
spec: | ||
containers: | ||
- name: rails-example | ||
image: rails-example | ||
ports: | ||
- containerPort: 3000 | ||
env: | ||
- name: POSTGRES_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: tiltfile | ||
key: postgres-password |