<commit_before>#!/bin/bash


function init(){

  if [ -f docker-compose.yml ]; then
    if [ "$1" = "-f" ]; then
      echo "Overwriting existing Dockerfile and docker-compose.yml"
      shift
    else
      echo ""
      echo "== Error =="
      echo "Detected already existing docker-compose.yml."
      echo "If you want to create a new one please delete "
      echo "it first or use -f to force the recreation."
      echo "==========="
      echo ""
      exit 1
    fi
  fi

  if [ -f .rde.conf ]; then
    echo "Loading rde configuration ..."
    source .rde.conf
  else
    if [ -n "$1" ]; then
      PROJECTNAME=$(printf '%s' "${1}" | tr -cd '[[:alnum:]]')
    else
      PROJECTNAME=$(printf '%s' "${PWD##*/}" | tr -cd '[[:alnum:]]')
    fi

    echo "Storing rde configuration ..."
    echo "PROJECTNAME=$PROJECTNAME" > .rde.conf
  fi
  echo "Creating project with projectname: $PROJECTNAME"
  echo "Creating Dockerfile ..."
  cat > Dockerfile <<EOF

FROM rails

EXPOSE 3000

RUN addgroup --gid $(id -g) rails
RUN useradd --uid $(id -u) --gid $(id -g) --home-dir /usr/src/app rails

WORKDIR /usr/src/app
CMD rails s -b 0.0.0.0

COPY ./Gemfile* /usr/src/app/
RUN bundle install --system
RUN mkdir -p /opt/rde
RUN cp Gemfile.lock /opt/rde

EOF
  echo "Creating docker compose file ..."
  cat > docker-compose.yml <<EOF
postgres:
  image: postgres
  volumes:
    - "/srv/docker/rde/postgres-data$(pwd):/var/lib/postgresql/data"
  environment:
    POSTGRES_PASSWORD: rails_db
    POSTGRES_USER: rails_db

rails:
  build: .
  working_dir: /usr/src/app
  user: "$(id -u):$(id -g)"
  volumes:
    - ".:/usr/src/app"
  environment:
    DB_HOST: postgres
  env_file:
    - .env
  links:
    - postgres
  ports:
    - "3000:3000"
EOF

  echo "creating .env file for your local environment variables ..."

  touch .env
  touch Gemfile

  amend_gitignore

}

function amend_gitignore() {
  if [ -f .gitignore ]; then
    if ! grep -Fxq "Dockerfile" .gitignore ; then
      echo "Dockerfile" >> .gitignore
    fi
    if ! grep -Fxq "docker-compose.yml" .gitignore ; then
      echo "docker-compose.yml" >> .gitignore
    fi<commit_msg>change dockerfile name to allow for standard default Dockerfile for automatic builds<commit_after>#!/bin/bash


function init(){

  if [ -f docker-compose.yml ]; then
    if [ "$1" = "-f" ]; then
      echo "Overwriting existing Dockerfile and docker-compose.yml"
      shift
    else
      echo ""
      echo "== Error =="
      echo "Detected already existing docker-compose.yml."
      echo "If you want to create a new one please delete "
      echo "it first or use -f to force the recreation."
      echo "==========="
      echo ""
      exit 1
    fi
  fi

  if [ -f .rde.conf ]; then
    echo "Loading rde configuration ..."
    source .rde.conf
  else
    if [ -n "$1" ]; then
      PROJECTNAME=$(printf '%s' "${1}" | tr -cd '[[:alnum:]]')
    else
      PROJECTNAME=$(printf '%s' "${PWD##*/}" | tr -cd '[[:alnum:]]')
    fi

    echo "Storing rde configuration ..."
    echo "PROJECTNAME=$PROJECTNAME" > .rde.conf
  fi
  echo "Creating project with projectname: $PROJECTNAME"
  echo "Creating Dockerfile ..."
  cat > DockerfileRDE <<EOF

FROM rails

EXPOSE 3000

RUN addgroup --gid $(id -g) rails
RUN useradd --uid $(id -u) --gid $(id -g) --home-dir /usr/src/app rails

WORKDIR /usr/src/app
CMD rails s -b 0.0.0.0

COPY ./Gemfile* /usr/src/app/
RUN bundle install --system
RUN mkdir -p /opt/rde
RUN cp Gemfile.lock /opt/rde

EOF
  echo "Creating docker compose file ..."
  cat > docker-compose.yml <<EOF
postgres:
  image: postgres
  volumes:
    - "/srv/docker/rde/postgres-data$(pwd):/var/lib/postgresql/data"
  environment:
    POSTGRES_PASSWORD: <PASSWORD>
    POSTGRES_USER: rails_db

rails:
  build: .
  dockerfile: DockerfileRDE
  working_dir: /usr/src/app
  user: "$(id -u):$(id -g)"
  volumes:
    - ".:/usr/src/app"
  environment:
    DB_HOST: postgres
  env_file:
    - .env
  links:
    - postgres
  ports:
    - "3000:3000"
EOF

  echo "creating .env file for your local environment variables ..."

  touch .env
  touch Gemfile

  amend_gitignore

}

function amend_gitignore() {
  if [ -f .gitignore ]; then
    if ! grep -Fxq "Dockerfile" .gitignore ; then
      echo "DockerfileRDE" >> .gitignore
    fi
    if ! grep -Fxq "docker-compose.yml" .gitignore ; then
      echo "docker-compose.yml" >> .gitignore
    fi
{'fraction_non_alphanumeric': 0.14514285714285713, 'fraction_numerical': 0.009142857142857144, 'mean_word_length': 2.473015873015873, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6279190', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1531, 'n_words': 462}