Skip to content
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

[proposal] Add node and yarn installation logic to dockerfile, bump ruby to 3.3.6, bump rails to 8.0.0 #23

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
ARG RUBY_VERSION=3.3.4
ARG RUBY_VERSION=3.3.6
FROM ruby:${RUBY_VERSION}

ARG NODE_VERSION=22
ARG YARN_VERSION=1.22.22

RUN curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
&& apt-get update \
&& apt-get install --yes --no-install-recommends nodejs \
&& npm install -g yarn@$YARN_VERSION

ARG RAILS_VERSION
# Install Rails based on the version specified but if not specified, install the latest version.
RUN if [ -z "$RAILS_VERSION" ] ; then gem install rails ; else gem install rails -v $RAILS_VERSION ; fi
13 changes: 12 additions & 1 deletion Dockerfile.unix
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
ARG RUBY_VERSION=3.3.4
ARG RUBY_VERSION=3.3.6
FROM ruby:${RUBY_VERSION}

ARG USER_ID=1000
ARG GROUP_ID=1000
RUN groupadd -g $GROUP_ID app && useradd -u $USER_ID -g app -m app

ARG NODE_VERSION=22
ARG YARN_VERSION=1.22.22

RUN curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
&& apt-get update \
&& apt-get install --yes --no-install-recommends nodejs \
&& npm install -g yarn@$YARN_VERSION

USER app

ARG RAILS_VERSION
# Install Rails based on the version specified but if not specified, install the latest version.
RUN if [ -z "$RAILS_VERSION" ] ; then gem install rails ; else gem install rails -v $RAILS_VERSION ; fi
32 changes: 16 additions & 16 deletions src/docker_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ mod tests {

#[test]
fn build_image() {
let command = DockerClient::build_image("3.2.3", "7.1.3", None, None);
let command = DockerClient::build_image("3.3.6", "8.0.0", None, None);

assert_eq!(command.get_program(), "docker");

Expand All @@ -101,19 +101,19 @@ mod tests {
&[
"build",
"--build-arg",
"RUBY_VERSION=3.2.3",
"RUBY_VERSION=3.3.6",
"--build-arg",
"RAILS_VERSION=7.1.3",
"RAILS_VERSION=8.0.0",
"-t",
"rails-new-3.2.3-7.1.3",
"rails-new-3.3.6-8.0.0",
"-",
]
);
}

#[test]
fn build_image_with_user_id() {
let command = DockerClient::build_image("3.2.3", "7.1.3", Some(1000), None);
let command = DockerClient::build_image("3.3.6", "8.0.0", Some(1000), None);

assert_eq!(command.get_program(), "docker");

Expand All @@ -124,21 +124,21 @@ mod tests {
&[
"build",
"--build-arg",
"RUBY_VERSION=3.2.3",
"RUBY_VERSION=3.3.6",
"--build-arg",
"RAILS_VERSION=7.1.3",
"RAILS_VERSION=8.0.0",
"--build-arg",
"USER_ID=1000",
"-t",
"rails-new-3.2.3-7.1.3",
"rails-new-3.3.6-8.0.0",
"-",
]
);
}

#[test]
fn build_image_with_group_id() {
let command = DockerClient::build_image("3.2.3", "7.1.3", None, Some(1000));
let command = DockerClient::build_image("3.3.6", "8.0.0", None, Some(1000));

assert_eq!(command.get_program(), "docker");

Expand All @@ -149,21 +149,21 @@ mod tests {
&[
"build",
"--build-arg",
"RUBY_VERSION=3.2.3",
"RUBY_VERSION=3.3.6",
"--build-arg",
"RAILS_VERSION=7.1.3",
"RAILS_VERSION=8.0.0",
"--build-arg",
"GROUP_ID=1000",
"-t",
"rails-new-3.2.3-7.1.3",
"rails-new-3.3.6-8.0.0",
"-",
]
);
}

#[test]
fn run_image() {
let command = DockerClient::run_image("3.2.3", "7.1.3", vec!["my_app".to_string()]);
let command = DockerClient::run_image("3.3.6", "8.0.0", vec!["my_app".to_string()]);

assert_eq!(command.get_program(), "docker");

Expand All @@ -182,7 +182,7 @@ mod tests {
&format!("{}:{}", current_dir, current_dir),
"-w",
current_dir,
"rails-new-3.2.3-7.1.3",
"rails-new-3.3.6-8.0.0",
"rails",
"new",
"my_app",
Expand All @@ -192,7 +192,7 @@ mod tests {

#[test]
fn get_help() {
let command = DockerClient::get_help("3.2.3", "7.1.3");
let command = DockerClient::get_help("3.3.6", "8.0.0");

assert_eq!(command.get_program(), "docker");

Expand All @@ -203,7 +203,7 @@ mod tests {
&[
"run",
"--rm",
"rails-new-3.2.3-7.1.3",
"rails-new-3.3.6-8.0.0",
"rails",
"new",
"--help",
Expand Down
10 changes: 5 additions & 5 deletions src/rails_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ pub struct Cli {
#[clap(trailing_var_arg = true, required = true)]
/// arguments passed to `rails new`
pub args: Vec<String>,
#[clap(long, short = 'u', default_value = "3.3.4")]
#[clap(long, short = 'u', default_value = "3.3.6")]
pub ruby_version: String,
#[clap(long, short = 'r', default_value = "7.2.0")]
#[clap(long, short = 'r', default_value = "8.0.0")]
pub rails_version: String,

#[command(subcommand)]
Expand All @@ -17,7 +17,7 @@ pub struct Cli {

#[derive(Subcommand)]
pub enum Commands {
/// Prints `rails new --help`
/// Print `rails new --help`
RailsHelp {},
}

Expand Down Expand Up @@ -54,8 +54,8 @@ mod tests {
let ruby_version = m.get_one::<String>("ruby_version").unwrap();
let rails_version = m.get_one::<String>("rails_version").unwrap();

assert_eq!(ruby_version, "3.3.4");
assert_eq!(rails_version, "7.2.0");
assert_eq!(ruby_version, "3.3.6");
assert_eq!(rails_version, "8.0.0");

Ok(())
}
Expand Down
Loading