This guide aims to help you set up a Docker development environment that enforces Semantic Versioning and Conventional Commits. By following these steps, you'll be able to develop your application within a Docker container, ensuring that you adhere to the conventions specified at semver.org and conventionalcommits.org.
- Docker Desktop installed on a Unix-compatible system
- Visual Studio Code installed
- Git installed
- Generate a new SSH key and add it to the SSH agent by following these instructions.
- Add the new SSH key to your GitHub account by following these instructions.
-
Open your terminal and navigate to your project directory.
cd path/to/your/project -
Create a
package.jsonfile with the following content:touch package.json
{ "name": "docker-dev-semver", "version": "1.0.0", "description": "## Introduction", "main": "index.js", "scripts": { "start": "node index.js", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" } -
Create an
index.jsfile with the following content:console.log("Hello, world!");
-
Create a Dockerfile for your development environment.
touch Dockerfile
Open the Dockerfile in a text editor and add the following content:
# Use an official Node runtime as base image FROM node:14 # Set the working directory in the container WORKDIR /usr/src/app # Install app dependencies COPY package*.json ./ RUN npm install # CommitGPT Configuration RUN echo '{\n "model": "text-davinci-003",\n "temperature": 0.5,\n "maxTokens": 2048\n}' > /usr/src/app/.commitgpt.json RUN echo 'suggest 10 commit messages based on the following diff:\n{{diff}}\ncommit messages should:\n - follow conventional commits\n - message format should be: <type>[scope]: <description>\nexamples:\n - fix(authentication): add password regex pattern\n - feat(storage): add new test cases' > /usr/src/app/.commitgpt-template # Set OpenAI API Key as an environment variable ENV OPENAI_API_KEY=your-openai-api-key # Install Semantic Versioning and Conventional Commits plugins RUN npm install -g semantic-release @commitlint/config-conventional @commitlint/cli commitizen # Git configuration (Optional) RUN git config --global user.name "Your Name" RUN git config --global user.email "youremail@example.com" RUN git config --global --add safe.directory /com.docker.devenvironments.code # Configure Git Trailers RUN echo "[trailers]" >> /root/.gitconfig && \ echo " key = \"Signed-off-by: \"" >> /root/.gitconfig && \ echo " value = \"Your Name <youremail@example.com>\"" >> /root/.gitconfig # Copy the current directory contents into the container COPY . . CMD ["npm", "start"]
-
Create a
docker-compose.yamlfile.touch docker-compose.yaml
Open the
docker-compose.yamlin a text editor and add the following content:version: "3.7" services: app: build: context: . dockerfile: Dockerfile ports: - "3000:3000" volumes: - ~/.ssh/id_rsa:/root/.ssh/id_rsa:ro
-
Build and run your Docker container.
docker-compose up --build
-
Create a Shareable Docker Dev Environment Link. Generate a shareable link for your Docker Dev Environment like the following:
https://open.docker.com/dashboard/dev-envs?url=https://github.com/YourUsername/YourRepoNameReplace
YourUsernameandYourRepoNamewith your GitHub username and repository name, respectively. https://open.docker.com/dashboard/dev-envs?url=https://github.com/Malnati/docker-dev-semver
-
Open Docker Desktop. Navigate to the Dev Environments tab.
-
Create a New Dev Environment. Click on the "New Environment" button and select your project directory where the
docker-compose.yamlandDockerfile-DevEnvironmentare located. -
Launch VSCode. Once the environment is created, click on the "Open in VSCode" button. This will launch Visual Studio Code with the remote container extension, connecting it to your Docker container.
-
Open Terminal in VSCode. Once VSCode is connected to your Docker container, open a new terminal window inside VSCode. This terminal will be running inside your Docker container.
-
Install Dependencies. Run the following command to install the dependencies specified in your
package.json:npm install
-
Initialize Commitizen.
commitizen init cz-conventional-changelog --save-dev --save-exact
-
Configure Commitlint. Create a
commitlint.config.jsfile and add the following content:module.exports = {extends: ['@commitlint/config-conventional']};
-
Set up Husky Hooks. Add the following hooks to your
package.json:"husky": { "hooks": { "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } }
-
Install ChatGPT SDK.
npm install chatgpt-sdk
-
Configure ChatGPT. Add your ChatGPT API keys and other configurations as environment variables or within your application code.
-
Log in to your Docker Hub account.
docker login
-
Tag your Docker image.
docker tag local-image-name:tagname new-repo-name:tagname
-
Push the Docker image to your Docker Hub repository.
docker push new-repo-name:tagname
-
Generate Shareable Link. If the "Share" button is not available in Docker Desktop, you can create a manual link:
https://open.docker.com/dashboard/dev-envs?url=https://github.com/Malnati/docker-dev-semver -
Update GitHub Repository. Add this shareable link to your GitHub repository
Git Trailers allow you to append metadata to your commit messages, which can be useful for tracking issues, authors, and other information. For more details, refer to the official Git Trailers documentation.
-
Install Git Trailers. Git Trailers are built into Git, so no additional installation is required.
-
Configure Git Trailers. You can configure Git Trailers in your
.gitconfigor within the repository's.git/configfile. Here's an example:[trailers] key = "Signed-off-by: " value = "Your Name <youremail@example.com>"
-
Use Git Trailers in Commit Messages. When you make a commit, you can include trailers at the end of your commit message like so:
feat: add new feature Signed-off-by: Your Name <youremail@example.com>
CommitGPT is a tool that leverages GPT-3 to generate commit messages automatically. This can be particularly useful for maintaining a consistent and descriptive commit history.
-
Install CommitGPT. To install CommitGPT, you can use npm:
npm install -g commitgpt
-
Configure CommitGPT. After installation, you'll need to set up your GPT-3 API key. You can do this by setting an environment variable:
export OPENAI_API_KEY="your-openai-api-key"
-
Use CommitGPT for Commits. Instead of using
git commit, you can now usecommitgptto generate a commit message automatically:commitgpt
This will stage all your changes and open an editor with a pre-filled commit message generated by GPT-3.
Zsh Autosuggestions is a plugin for Zsh that suggests commands as you type, based on your command history. This can be particularly useful for speeding up your workflow.
-
Update the Dockerfile. Add the following lines to your
Dockerfile-DevEnvironmentto install Zsh:RUN apt-get update && apt-get install -y zsh -
Change Default Shell to Zsh. Add this line to your
Dockerfile-DevEnvironmentto change the default shell to Zsh:SHELL ["/bin/zsh", "-c"]
-
Clone the Zsh Autosuggestions Repository. Add the following line to your
Dockerfile-DevEnvironmentto clone the repository:RUN git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions -
Enable the Plugin. Add the following line to your
Dockerfile-DevEnvironmentto enable the plugin:RUN echo "source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
After making these changes, rebuild your Docker image to apply them:
docker-compose build