├── readme ├── .env ├── srcs ├── .env ├── docker-compose.yml ├── config │ ├── .zshrc │ └── .vimrc └── Dockerfile ├── custom.sh ├── docker-compose.yml ├── Makefile ├── config ├── .zshrc └── .vimrc ├── Dockerfile ├── .github └── workflows │ └── tag-docker-generator.yml └── README.md /readme: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | DLC_WORK_VOLUME_ORIGIN="${HOME}" 2 | -------------------------------------------------------------------------------- /srcs/.env: -------------------------------------------------------------------------------- 1 | DLC_WORK_VOLUME_ORIGIN="${HOME}" 2 | -------------------------------------------------------------------------------- /custom.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | currentfolder=${PWD} 4 | cd ~ 5 | echo "Which is the folder of your host computer you want to find in the container?:" 6 | printf "${HOME}"/ 7 | read -e origin 8 | 9 | echo DLC_WORK_VOLUME_ORIGIN=\""${HOME}"/$origin\"\ > $currentfolder/srcs/.env 10 | 11 | cd $currentfolder 12 | 13 | make down 14 | docker volume rm srcs_ubuntu_gcc_clang 15 | make 16 | docker exec -it ubuntu /bin/zsh 17 | -------------------------------------------------------------------------------- /srcs/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | ubuntu: 5 | image: ubuntu_gcc_clang 6 | container_name: ubuntu 7 | build: ./ 8 | restart: on-failure 9 | volumes: 10 | - ubuntu_gcc_clang:/home/marvin/docker 11 | tty: true 12 | 13 | volumes: 14 | ubuntu_gcc_clang: 15 | driver: local 16 | driver_opts: 17 | type: none 18 | o: bind 19 | device: ${DLC_WORK_VOLUME_ORIGIN} 20 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | ubuntu: 5 | image: ubuntu_gcc_clang 6 | container_name: ubuntu 7 | build: ./ 8 | ports: 9 | - 3333:3333 10 | restart: on-failure 11 | volumes: 12 | - ubuntu_gcc_clang:${DLC_WORK_VOLUME_DESTINATION} 13 | working_dir: ${DLC_WORKING_DIR} 14 | tty: true 15 | 16 | volumes: 17 | ubuntu_gcc_clang: 18 | driver: local 19 | driver_opts: 20 | type: none 21 | o: bind 22 | device: ${DLC_WORK_VOLUME_ORIGIN} 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: clean build 2 | @cd srcs/ && docker-compose up -d 3 | 4 | build: 5 | @cd srcs/ && docker-compose build 6 | 7 | fbuild: 8 | @cd srcs/ && docker-compose build --no-cache 9 | 10 | up: 11 | @cd srcs/ && docker rmi $(shell docker images -f "dangling=true" -qa) && docker-compose up -d 12 | 13 | down: 14 | @cd srcs/ && docker-compose down 15 | 16 | logs: 17 | @cd srcs/ && docker-compose logs -f 18 | 19 | clean: down 20 | @docker volume prune -f 21 | 22 | fclean: clean 23 | @docker image rm ubuntu_gcc_clang 24 | 25 | prune: 26 | @docker system prune -af 27 | 28 | space: 29 | @docker system df 30 | 31 | re: fclean build 32 | 33 | .PHONY: all build up down logs clean fclean re space mariadb wordpress nginx 34 | -------------------------------------------------------------------------------- /config/.zshrc: -------------------------------------------------------------------------------- 1 | export ZSH="$HOME/.oh-my-zsh" 2 | 3 | ZSH_THEME="robbyrussell" 4 | 5 | plugins=(git) 6 | 7 | source $ZSH/oh-my-zsh.sh 8 | 9 | # xterm configuration 10 | export TERM=xterm-256color 11 | 12 | # clang configuration 13 | export ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-6.0/bin/llvm-symbolizer 14 | export PATH=/clang_15/bin:$PATH 15 | export LD_LIBRARY_PATH=/clang_15/lib:$LD_LIBRARY_PATH 16 | 17 | # User configuration 18 | alias ce='gcc -Wall -Wextra -Werror' 19 | alias cw='gcc -Wall -Wextra' 20 | alias csanitize='gcc -Wall -Wextra -Werror -fsanitize=address' 21 | 22 | alias g='g++ -Wall -Wextra -Werror' 23 | alias c='clang++ -Wall -Wextra -Werror' 24 | alias e='g srcs/test*.cpp > /dev/pts/1; c srcs/test*.cpp > /dev/pts/2' 25 | -------------------------------------------------------------------------------- /srcs/config/.zshrc: -------------------------------------------------------------------------------- 1 | export ZSH="$HOME/.oh-my-zsh" 2 | 3 | ZSH_THEME="robbyrussell" 4 | 5 | plugins=(git) 6 | 7 | source $ZSH/oh-my-zsh.sh 8 | 9 | # xterm configuration 10 | export TERM=xterm-256color 11 | 12 | # clang configuration 13 | export ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-6.0/bin/llvm-symbolizer 14 | export PATH=/clang_15/bin:$PATH 15 | export LD_LIBRARY_PATH=/clang_15/lib:$LD_LIBRARY_PATH 16 | 17 | # User configuration 18 | alias ce='gcc -Wall -Wextra -Werror' 19 | alias cw='gcc -Wall -Wextra' 20 | alias csanitize='gcc -Wall -Wextra -Werror -fsanitize=address' 21 | 22 | alias g='g++ -Wall -Wextra -Werror' 23 | alias c='clang++ -Wall -Wextra -Werror' 24 | alias e='g srcs/test*.cpp > /dev/pts/1; c srcs/test*.cpp > /dev/pts/2' 25 | -------------------------------------------------------------------------------- /config/.vimrc: -------------------------------------------------------------------------------- 1 | syntax on 2 | 3 | colorscheme pablo 4 | 5 | " Deal with multiple unsaved buffers 6 | set hidden 7 | 8 | set mouse=a 9 | set number 10 | 11 | set tabstop=4 12 | set shiftwidth=4 13 | set noexpandtab 14 | 15 | set encoding=utf-8 16 | set showcmd 17 | set ruler " Show the current line and colunm on the bottom line 18 | set cursorline " Show the current line with a line 19 | set backspace=indent,eol,start 20 | 21 | " Better seach 22 | set ignorecase 23 | set smartcase 24 | set incsearch 25 | set showmatch 26 | set hlsearch 27 | 28 | " Show special chars 29 | set listchars=tab:→\ ,trail:· 30 | set list 31 | 32 | " Auto completion 33 | set wildmenu 34 | 35 | " Make it behave like bash completion 36 | set wildmode=list:longest 37 | 38 | " Ignore the files we can't edit 39 | set wildignore=*.docx,*.jpg,*.png,*.jpeg,*.gif,*.pdf,*.out 40 | 41 | " Indent with Tab in visual mode 42 | :vmap > 43 | :vmap < 44 | -------------------------------------------------------------------------------- /srcs/config/.vimrc: -------------------------------------------------------------------------------- 1 | syntax on 2 | 3 | colorscheme pablo 4 | 5 | " Deal with multiple unsaved buffers 6 | set hidden 7 | 8 | set mouse=a 9 | set number 10 | 11 | set tabstop=4 12 | set shiftwidth=4 13 | set noexpandtab 14 | 15 | set encoding=utf-8 16 | set showcmd 17 | set ruler " Show the current line and colunm on the bottom line 18 | set cursorline " Show the current line with a line 19 | set backspace=indent,eol,start 20 | 21 | " Better seach 22 | set ignorecase 23 | set smartcase 24 | set incsearch 25 | set showmatch 26 | set hlsearch 27 | 28 | " Show special chars 29 | set listchars=tab:→\ ,trail:· 30 | set list 31 | 32 | " Auto completion 33 | set wildmenu 34 | 35 | " Make it behave like bash completion 36 | set wildmode=list:longest 37 | 38 | " Ignore the files we can't edit 39 | set wildignore=*.docx,*.jpg,*.png,*.jpeg,*.gif,*.pdf,*.out 40 | 41 | " Indent with Tab in visual mode 42 | :vmap > 43 | :vmap < 44 | -------------------------------------------------------------------------------- /srcs/Dockerfile: -------------------------------------------------------------------------------- 1 | #https://baykara.medium.com/installing-clang-10-in-a-docker-container-4c24a4538af2 2 | 3 | #FROM ubuntu:latest 4 | FROM ubuntu:18.04 5 | 6 | RUN apt-get update && apt-get install -y \ 7 | sudo \ 8 | curl \ 9 | zsh \ 10 | zip \ 11 | git \ 12 | vim \ 13 | build-essential \ 14 | valgrind \ 15 | readline-common \ 16 | libreadline-dev \ 17 | clang \ 18 | && rm -rf /var/lib/apt/lists/* && \ 19 | useradd -m marvin && \ 20 | echo "marvin ALL=(ALL) ALL" > /etc/sudoers.d/marvin && \ 21 | chmod 0440 /etc/sudoers.d/marvin && \ 22 | passwd -d marvin && \ 23 | chsh -s zsh marvin 24 | 25 | USER marvin 26 | 27 | COPY --chown=marvin:marvin config/.vimrc config/.zshrc /home/marvin/ 28 | 29 | RUN curl -s https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh --output /home/marvin/install.sh && \ 30 | /bin/sh /home/marvin/install.sh --unattended --skip-chsh --keep-zshrc && \ 31 | rm /home/marvin/install.sh 32 | 33 | WORKDIR /home/marvin/docker 34 | 35 | ENTRYPOINT ["/bin/zsh"] -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | #https://baykara.medium.com/installing-clang-10-in-a-docker-container-4c24a4538af2 2 | 3 | #FROM ubuntu:latest 4 | FROM ubuntu:18.04 5 | 6 | RUN apt-get update && apt-get install -y \ 7 | curl \ 8 | build-essential \ 9 | zsh \ 10 | fontconfig \ 11 | zip \ 12 | git \ 13 | clang \ 14 | vim \ 15 | valgrind \ 16 | neofetch \ 17 | readline-common \ 18 | libreadline-dev \ 19 | && rm -rf /var/lib/apt/lists/* 20 | 21 | RUN cd ~ && curl -SL --output Meslo.zip https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip && \ 22 | mkdir -p .fonts && \ 23 | unzip Meslo.zip -d .fonts && \ 24 | cd .fonts && \ 25 | rm *Windows* && \ 26 | cd ~ && \ 27 | rm Meslo.zip && \ 28 | fc-cache -fv 29 | 30 | RUN git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k && \ 31 | echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc && \ 32 | echo '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' >> ~/.zshrc 33 | 34 | ADD powerlevel10k.zsh-theme ~/powerlevel10k/powerlevel10k.zsh-theme 35 | ADD .p10k.zsh /root/.p10k.zsh 36 | RUN echo "export PATH=/clang_15/bin:$PATH" >> ~/.zshrc && \ 37 | echo "export LD_LIBRARY_PATH=/clang_15/lib:$LD_LIBRARY_PATH" >> ~/.zshrc && \ 38 | echo "export TERM=xterm-256color" >> ~/.zshrc && \ 39 | echo "alias g='g++ -Wall -Wextra -Werror'" >> ~/.zshrc && \ 40 | echo "alias c='clang++ -Wall -Wextra -Werror'" >> ~/.zshrc && \ 41 | echo "alias e='g srcs/test*.cpp > /dev/pts/1; c srcs/test*.cpp > /dev/pts/2'" >> ~/.zshrc 42 | 43 | ENV ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-6.0/bin/llvm-symbolizer 44 | -------------------------------------------------------------------------------- /.github/workflows/tag-docker-generator.yml: -------------------------------------------------------------------------------- 1 | name: Tag and DockerHub image generator 2 | 3 | on: 4 | pull_request: 5 | types: [closed] 6 | branches: [master] 7 | 8 | jobs: 9 | tag-release: 10 | runs-on: ubuntu-latest 11 | outputs: 12 | newtag: ${{ steps.mayorrelease.outputs.new_tag }} 13 | steps: 14 | - name: Checkout Repository 15 | uses: actions/checkout@v2 16 | with: 17 | ref: master 18 | 19 | - name: Fetch tags 20 | run: git fetch --tags --prune 21 | 22 | - name: Mayor release 23 | id: mayorrelease 24 | if: contains(github.event.pull_request.labels.*.name, 'mayor update') 25 | env: 26 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 27 | run: | 28 | current_tag=$(git describe --tags $(git rev-list --tags --max-count=1)) 29 | echo "Current tag: $current_tag" 30 | echo "Mayor update" 31 | new_tag=$(echo "$current_tag" | awk -F. -v OFS=. '{print $1,$2+1,0}') 32 | echo "New tag: $new_tag" 33 | echo "new_tag=$new_tag" >> $GITHUB_OUTPUT 34 | git tag $new_tag 35 | git push origin $new_tag 36 | 37 | - name: Minor release 38 | if: contains(github.event.pull_request.labels.*.name, 'mayor update') == false 39 | env: 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | run: | 42 | current_tag=$(git describe --tags $(git rev-list --tags --max-count=1)) 43 | echo "Current tag: $current_tag" 44 | echo "Minor update" 45 | new_tag=$(echo "$current_tag" | awk -F. '{$NF = $NF + 1;} 1' OFS=.) 46 | echo "New tag: $new_tag" 47 | git tag $new_tag 48 | git push origin $new_tag 49 | 50 | dockerhub-update: 51 | needs: tag-release 52 | if: contains(github.event.pull_request.labels.*.name, 'mayor update') 53 | runs-on: ubuntu-latest 54 | name: Push Docker image to Docker Hub 55 | steps: 56 | - name: Check out the repo 57 | uses: actions/checkout@v3 58 | 59 | - name: Log in to Docker Hub 60 | uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 61 | with: 62 | username: ${{ secrets.DOCKER_USERNAME }} 63 | password: ${{ secrets.DOCKER_PASSWORD }} 64 | 65 | - name: Extract metadata (tags, labels) for Docker 66 | id: meta 67 | uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 68 | with: 69 | images: yeta1990/gcc-clang-42 70 | 71 | - name: Build and push Docker image 72 | uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc 73 | with: 74 | context: ./srcs/ 75 | push: true 76 | tags: yeta1990/gcc-clang-42:latest,yeta1990/gcc-clang-42:${{needs.tag-release.outputs.newtag}} 77 | labels: ${{ steps.meta.outputs.labels }} 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | demo-docker 2 | 3 | # 🐳 Ubuntu for 42 computers in a single command 4 | Docker container based in ubuntu18 to compile your 42 C and C++ projects with gcc7 and clang15. 5 | 6 | ## 🤔 Is this tool useful for me? 7 | **TL:DR; 8 | The original purpose of this project is to find leaks and segfaults in seconds compiling your C and C++ programs with `-g3 -fsanitize=address`, without the limitations of the 42 iMacs** 9 | 10 | If you are in any of these situations, this tool is definitely useful for you: 11 | - You are working in a 42 iMac. 12 | - You don't really know if your program leaks memory. 13 | - You don't know what is generating a segfault in your program. 14 | - You want to use valgrind or gdb. 15 | - You usually debug with printf. 16 | - You are trying to find leaks with the system leaks call, i.e.: `system("leaks a.out");`. 17 | 18 | ## 📘 Features 19 | - It includes **gcc, clang, valgrind** and **ohmyzsh** 20 | - Real-time synchronization with your **vim** or **VStudio**: mounts a volume in your working directory so you can edit as you normally do it and then compile and execute in the ubuntu container. 21 | - Includes **readline** library, needed to compile Minishell project just adding flag -lreadline. 22 | 23 | ## ⚙️ Requirements 24 | 25 | 1. Docker installed and running. (In iMac you'll find it in the MSC). 26 | 2. Change the cache directory of docker to goinfre: `Docker desktop, Preferences->Resources: Advanced->Disk image location: /goinfre/your_42_user` 27 | 28 | ## 🖥 Usage 29 | ### Option 1: the easiest way (1 command, without cloning the repo) 30 | In your terminal, go to the folder you want to work with and type: 31 | ```zsh 32 | docker run -it --rm -v $PWD:/home/marvin/docker yeta1990/gcc-clang-42 33 | ``` 34 | 35 | The container stops and is removed once you leave the terminal session. 36 | 37 | ### Option 2: option 1 but more comfortable (1 alias, without cloning the repo) 38 | Feel like a pro adding this alias in your `~/.zshrc` 39 | ```zsh 40 | alias ubuntu='docker run -it --rm -v $PWD:/home/marvin/docker yeta1990/gcc-clang-42' 41 | ``` 42 | 43 | Then, you'll only need to type `ubuntu` whenever you want to open a terminal of your ubuntu container. 44 | The container stops and is removed once you leave the terminal session. 45 | 46 | ### Option 3: building the image 47 | The mounted volume will be your whole $HOME directory. Type: 48 | 49 | ```zsh 50 | git clone https://github.com/yeta1990/docker-gcc-clang /sgoinfre/students/$USER/docker-gcc-clang && cd /sgoinfre/students/$USER/docker-gcc-clang && make 51 | ``` 52 | 53 | Other actions: 54 | - Open more ubuntu terminals by: 55 | `docker exec -it ubuntu /bin/zsh` 56 | - Stop the container: `make down` 57 | - Clean everything: `make fclean` 58 | 59 | ### Option 4: build the image and set the working directory 60 | Run `./custom.sh` and specify the directory you want to mount into the container. 61 | Once you run this script, it's no necessary to execute it again, just type `make`, the working directory is stored in srcs/.env. 62 | Other actions: 63 | - Open more ubuntu terminals by: 64 | `docker exec -it ubuntu /bin/zsh` 65 | - Stop the container: `make down` 66 | - Clean everything: `make fclean` 67 | 68 | ## 👷 Contributors 69 | 70 | [Jkutkut](https://github.com/Jkutkut) has improved the Dockerfile and has uploaded the image to dockerhub. 71 | 72 | [Josgarci](https://github.com/PepeGF) has improved the Dockerfile by adding features such as the readline library. 73 | 74 | --------------------------------------------------------------------------------