|
| 1 | +FROM ubuntu:focal |
| 2 | + |
| 3 | +### base ### |
| 4 | +ENV DEBIAN_FRONTEND=noninteractive LANG=en_US.UTF-8 |
| 5 | +RUN yes | unminimize \ |
| 6 | + && apt-get install -yq \ |
| 7 | + curl \ |
| 8 | + wget \ |
| 9 | + acl \ |
| 10 | + zip \ |
| 11 | + unzip \ |
| 12 | + bash-completion \ |
| 13 | + build-essential \ |
| 14 | + jq \ |
| 15 | + locales \ |
| 16 | + software-properties-common \ |
| 17 | + libpq-dev \ |
| 18 | + sudo \ |
| 19 | + git \ |
| 20 | + graphviz=2.42.2-3build2 \ |
| 21 | + psmisc \ |
| 22 | + redis-server=5:5.0.7-2ubuntu0.1 \ |
| 23 | + && locale-gen en_US.UTF-8 \ |
| 24 | + && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* \ |
| 25 | + # Container user |
| 26 | + # '-l': see https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user |
| 27 | + && useradd -l -u 33334 -G sudo -md /home/student -s /bin/bash -p student student \ |
| 28 | + # Passwordless sudo for users in the 'sudo' group |
| 29 | + && sed -i.bkp -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers |
| 30 | +ENV HOME=/home/student |
| 31 | + |
| 32 | +### Student user ### |
| 33 | +USER student |
| 34 | +# Use sudo so that user does not get sudo usage info on (the first) login |
| 35 | +RUN sudo mkdir -p $HOME \ |
| 36 | + && sudo echo "Running 'sudo' for container: success" && \ |
| 37 | + # Create .bashrc.d folder and source it in the bashrc |
| 38 | + mkdir /home/student/.bashrc.d && \ |
| 39 | + (echo; echo "for i in \$(ls \$HOME/.bashrc.d/*); do source \$i; done"; echo) >> /home/student/.bashrc \ |
| 40 | + # Install Ruby with RVM |
| 41 | + && curl -sSL https://rvm.io/mpapis.asc | gpg --import - \ |
| 42 | + && curl -sSL https://rvm.io/pkuczynski.asc | gpg --import - \ |
| 43 | + && curl -fsSL https://get.rvm.io | bash -s stable \ |
| 44 | + && bash -lc " \ |
| 45 | + rvm requirements \ |
| 46 | + && rvm install 3.4.1 \ |
| 47 | + && rvm use 3.4.1 --default \ |
| 48 | + && rvm rubygems current \ |
| 49 | + && gem install bundler:2.6.5 --no-document" \ |
| 50 | + && echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*' >> /home/student/.bashrc.d/70-ruby && echo "rvm_gems_path=/home/student/.rvm" > ~/.rvmrc |
| 51 | + |
| 52 | +ENV GEM_HOME=/home/student/.rvm/gems/ruby-3.4.1:/workspaces/.rvm \ |
| 53 | + GEM_PATH=/home/student/.rvm/gems/ruby-3.4.1:/home/student/.rvm/gems/ruby-3.4.1@global \ |
| 54 | + PATH=/home/student/.rvm/gems/ruby-3.4.1/bin:/home/student/.rvm/gems/ruby-3.4.1@global/bin:/home/student/.rvm/rubies/ruby-3.4.1/bin:/home/student/.rvm/bin:/workspaces/.rvm/bin:$PATH |
| 55 | + |
| 56 | +WORKDIR /rails-template |
| 57 | + |
| 58 | +# Pre-install gems into /rails-template/gems/ |
| 59 | +COPY --chown=student:student Gemfile Gemfile.lock /rails-template/ |
| 60 | +RUN /bin/bash -l -c "bundle config set --local path '/home/student/.bundle' && bundle install" \ |
| 61 | + # Install postgresql 16 |
| 62 | + && sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt `lsb_release -cs`-pgdg main" > /etc/apt/sources.list.d/pgdg.list' \ |
| 63 | + && wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - \ |
| 64 | + && sudo apt-get update \ |
| 65 | + && sudo apt-get install -y postgresql-16 postgresql-contrib-16 |
| 66 | + |
| 67 | +# Setup PostgreSQL configuration |
| 68 | +ENV PATH="$PATH:/usr/lib/postgresql/16/bin" PGDATA="/workspaces/.pgsql/data" |
| 69 | +RUN sudo mkdir -p $PGDATA \ |
| 70 | + && mkdir -p ~/.pg_ctl/bin ~/.pg_ctl/sockets \ |
| 71 | + && printf '#!/bin/bash\n[ ! -d $PGDATA ] && mkdir -p $PGDATA && initdb -D $PGDATA\npg_ctl -D $PGDATA -l ~/.pg_ctl/log -o "-k ~/.pg_ctl/sockets" start\n' > ~/.pg_ctl/bin/pg_start \ |
| 72 | + && printf '#!/bin/bash\npg_ctl -D $PGDATA -l ~/.pg_ctl/log -o "-k ~/.pg_ctl/sockets" stop\n' > ~/.pg_ctl/bin/pg_stop \ |
| 73 | + && chmod +x ~/.pg_ctl/bin/* \ |
| 74 | + && sudo addgroup dev \ |
| 75 | + && sudo adduser student dev \ |
| 76 | + && sudo chgrp -R dev $PGDATA \ |
| 77 | + && sudo chmod -R 775 $PGDATA \ |
| 78 | + && sudo setfacl -dR -m g:staff:rwx $PGDATA \ |
| 79 | + && sudo chmod 777 /var/run/postgresql \ |
| 80 | + # This is a bit of a hack. At the moment we have no means of starting background |
| 81 | + # tasks from a Dockerfile. This workaround checks, on each bashrc eval, if the |
| 82 | + # PostgreSQL server is running, and if not starts it. |
| 83 | + && printf "\n# Auto-start PostgreSQL server.\n[[ \$(pg_ctl status | grep PID) ]] || pg_start > /dev/null\n" >> ~/.bashrc |
| 84 | +ENV PATH="$PATH:$HOME/.pg_ctl/bin" PGHOSTADDR="127.0.0.1" PGDATABASE="postgres" |
| 85 | + |
| 86 | + |
| 87 | +RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - \ |
| 88 | + # Install Node.js and Yarn |
| 89 | + && sudo apt-get install -y nodejs \ |
| 90 | + && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - \ |
| 91 | + && echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list \ |
| 92 | + && sudo apt-get update \ |
| 93 | + && sudo apt-get install -y yarn \ |
| 94 | + && sudo npm install -g n \ |
| 95 | + && sudo n 18 \ |
| 96 | + && hash -r \ |
| 97 | + && sudo rm -rf /var/lib/apt/lists/* \ |
| 98 | + # Add thoughtbot style bash prompt |
| 99 | + && sudo wget -qO ./prompt "https://gist.githubusercontent.com/jelaniwoods/7e5db8d72b3dfac257b7eb562cfebf11/raw/af43083d91c0eb1489059a2ad9c39474a34ddbda/thoughtbot-style-prompt" \ |
| 100 | + && /bin/bash -l -c "cat ./prompt >> ~/.bashrc" \ |
| 101 | + # Set git config |
| 102 | + && git config --global push.default upstream \ |
| 103 | + && git config --global merge.ff only \ |
| 104 | + && git config --global alias.aa '!git add -A' \ |
| 105 | + && git config --global alias.cm '!f(){ git commit -m "${*}"; };f' \ |
| 106 | + && git config --global alias.acm '!f(){ git add -A && git commit -am "${*}"; };f' \ |
| 107 | + && git config --global alias.as '!git add -A && git stash' \ |
| 108 | + && git config --global alias.p 'push' \ |
| 109 | + && git config --global alias.sla 'log --oneline --decorate --graph --all' \ |
| 110 | + && git config --global alias.co 'checkout' \ |
| 111 | + && git config --global alias.cob 'checkout -b' \ |
| 112 | + && git config --global --add --bool push.autoSetupRemote true \ |
| 113 | + && git config --global core.editor "code --wait" \ |
| 114 | + # Add g alias for git status |
| 115 | + && echo "# No arguments: 'git status'\n\ |
| 116 | +# With arguments: acts like 'git'\n\ |
| 117 | +g() {\n\ |
| 118 | + if [[ \$# > 0 ]]; then\n\ |
| 119 | + git \$@\n\ |
| 120 | + else\n\ |
| 121 | + git status\n\ |
| 122 | + fi\n\ |
| 123 | +}\n# Complete g like git\n\ |
| 124 | +source /usr/share/bash-completion/completions/git\n\ |
| 125 | +__git_complete g __git_main" >> ~/.bash_aliases \ |
| 126 | + # Add other aliases |
| 127 | + && echo "alias be='bundle exec'" >> ~/.bash_aliases \ |
| 128 | + && echo "alias grade='rake grade'" >> ~/.bash_aliases \ |
| 129 | + && echo "alias grade:reset_token='rake grade:reset_token'" >> ~/.bash_aliases \ |
| 130 | + && echo 'export PATH="$PWD/bin:$PATH"' >> ~/.bashrc \ |
| 131 | + && echo "nohup /workspaces/*/bin/postgres-monitor > /dev/null 2>&1 &" >> ~/.bashrc \ |
| 132 | + && echo "# Configure bundler and RVM paths" >> ~/.bashrc \ |
| 133 | + && echo 'export BUNDLE_PATH="/home/student/.bundle"' >> ~/.bashrc \ |
| 134 | + && echo 'export GEM_HOME="/home/student/.rvm/gems/ruby-3.4.1"' >> ~/.bashrc \ |
| 135 | + && echo 'export GEM_PATH="/home/student/.rvm/gems/ruby-3.4.1:/home/student/.rvm/gems/ruby-3.4.1@global"' >> ~/.bashrc |
0 commit comments