- Install Docker
- Install Docker compose
- Install Git and configure it
- Create a GitHub repository for your project/course
- Clone your repository to your local machine
- Download setup.sh script into your repository and run it
$ cd <your-repository>$ curl -o setup.sh https://raw.githubusercontent.com/rambasnet/course-container/main/setup.sh$ bash setup.sh
- follow the instructions here: https://www.techrepublic.com/article/install-docker-chromeos/
- You may have to explictly activate docker group everytime:
$ newgrp docker
- Clones this repository into your working directory
- Removes this repo specific files and folder and keeps everything else
- Deletes the cloned repository and other files and folders not listed above
-
Update the Dockerfile as needed for your project
- E.g., if you need to install any Linux packages, add the package to the end of
apt install -yline - after the docker is built, it runs as a non-root user
userwith sudo privileges - the default working directory is
/home/user - your repository is mounted to
/home/user/<your-repository> - no password is required for sudo commands
- E.g., if you need to install any Linux packages, add the package to the end of
-
Update the Makefile as needed for your project
- Makefile is used by git hooks to run test before pushing main to GitHub
-
Update the script.sh as needed for your project
- you may rarely need to change the script.sh file
-
Update the requirements.py as needed for your project
- this file is used by Docker to install Python packages
-
Update .github/workflows/ci-test.yml as needed for your project
- this file is used by GitHub Actions to run tests on push to main
-
Update ci-cd-requirements.txt as needed for your project
- this file is used by GitHub Actions to install Python packages
-
Update .githooks/pre-commit as needed for your project
- this file is run by git hooks before commmitting to any branch
-
Update .githooks/pre-push as needed for your project
- this file is run by git hooks before pushing to any branch
-
Make sure the git hooks are executable
$ chmod +x .githooks/pre-commit$ chmod +x .githooks/pre-push
-
Make sure core.hooksPath is set to
.githooksby default it is set to.git/hooks
$ git config core.hooksPath .githooks- Make sure git is installed and configured to push to remote
git config --global user.email "[email protected]"
git config --global user.name "Your Name"- default container name is
- edit
.envfile to change the course specific names as OOP, CS0, etc. - run the following docker commands
docker-compose up -d
docker ps
docker exec -it <container-name> zsh- if you modify
Dockerfileorrequirements.txtfile, you must rebuild the image
docker-compose up -d --build- to exit container, run the following command on the container Terminal
exit- to stop the container, run the following command on the host Terminal
docker-compose down- if you want to rebuild the container (after any changes to Dockerfile or requirements.txt), run the following command on the host Terminal
docker-compose up -d --build$ cd <your-repository>$ bash ./run-docker.sh
- Builds the Docker image
- Runs the Docker container
- Mounts your repository to the Docker container
- Sets the working directory to your repository
- Configures git to use the git hooks in your repository
- Runs the script.sh file in the Docker container
git status- check the status of the repositorygit add <file-name>- add a file to the staging areagit commit -m "<commit-message>"- commit the changesgit push- push the changes to GitHub
- learn more about git branch management
- CMU advanced courses deosn't allow committing to the main branch
- only merge and push to main branch allowed
- CMU courses recommend and enforce using a branch name that starts with:
lab|project|assignment|homework|issue|dev|feature|bugfix|improvement|library|prerelease|release|hotfixmain- the main branch - only merge and push to main branch allowed- the main branch is protected and cannot be deleted
- the main branch is the default branch
- the main branch is the production branch
- the main branch is the release branch from which tags and releases are made
issue/<#>- the issue branch- the issue branch is used to fix an issue, bug, or add a new feature
- the issue branch is created from the main branch
- the issue branch is merged to the main branch
feature/<feature-name>- the feature branchbug/<bug-name>- the bug branchhotfix/<hotfix-name>- the hotfix branchrelease/<release-name>- the release branchlab/<lab-name>- the lab branch for lab coursesproject/<project-name>- the project branch for various sub projects within a courseassignment/<assignment-name>- the assignment branch for various assignments within a course
$ cd <your-repository>$ git checkout main$ git pull$ git branch# list all branches$ git checkout -b <new-branch-name># create a new branch and switch to it$ git push -u origin <new-branch-name># push the new branch to GitHub and set the upstream$ git add <file-name># add a file to the staging area$ git commit -m "<commit-message>"# commit the changes$ git push# push the changes to GitHub to the current branch
$ cd <your-repository>$ git branch -m <old-branch-name> <new-branch-name># rename a branch; optional old-branch-name if you're on the old-branch-name$ git push origin -u <new-branch-name># push the new branch to GitHub and set the upstream
$ cd <your-repository>$ git checkout <branch-name>- switch to an existing branch
$ cd <your-repository>$ git branch- list all branches$ git branch -a- list all branches including remote branches$ git branch -r- list all remote branches
- committing and pushing to main is not allowed
- you must work on a branch and merge it to main after all the checks and tests pass on the branch
- you can then push and tag the main branch
$ cd <your-repository>- make sure your tests pass on the branch you want to merge to main
$ git checkout main$ git pull$ git merge <branch-name># merge the branch to main$ git push# push the changes to GitHub
- you can only delete a branch that is not currently checked out
- you can keep the merged branch or delete it
- for courses, keep all the branches as proof of your work
$ cd <your-repository>$ git branch -d <branch-name># delete the branch locally$ git push origin --delete <branch-name># delete the branch on GitHub
- you can revert a commit on any branch
$ cd <your-repository>$ git checkout <branch-name># switch to the branch$ git log# find the commit hash you want to revert$ git revert <commit-hash># revert the commit$ git push# push the changes to GitHub
- you can revert a merge on any branch
$ cd <your-repository>$ git checkout <branch-name># switch to the branch$ git log# find the commit hash you want to revert$ git revert -m 1 <commit-hash># revert the merge commit$ git push# push the changes to GitHub
- you can revert a merge conflict on any branch
$ cd <your-repository>$ git checkout <branch-name># switch to the branch$ git log# find the commit hash you want to revert$ git revert -m 1 <commit-hash># revert the merge commit$ git push# push the changes to GitHub
- learn more about git tagging
- Tags are used to mark a specific point in the history of a repository like a release
- Tags are immutable and cannot be changed once created
- Tags once created needs to be pushed to GitHub
- Assignments/Labs/Projects completions can be tagged and pushed to GitHub as a release
- follow the naming convention for tags specified in the course
- must tag to submit the assignment/lab/project
- tag name must be unique across all branches
$ cd <your-repository>$ git tag -a <tag-name> -m "<tag-message>"# create a tag- e.g.,
$ git tag -a assignment-1 -m "Final Submission of Assignment/1"
- e.g.,
$ git push origin <tag-name># push the tag to GitHub- git tag -d # delete a tag locally
- git tag # show all tags
- Kattis-cli is already installed in the Docker container
- See this document for Kattis setup and usage