Continuously updated…
1. Golang
- Use trimpath to remove the build path, avoiding exposure of build path information
| |
Before adding it, a panic prints the path /Users/shaowenchen/Code/Github/ops/main.go; after adding it, a panic prints main.go.
- -ldflags “-w -s” removes debug information and reduces the binary size
| |
55 MB before adding it, 44 MB after.
2. Python
- Compile ahead of time to generate pyc files
| |
Although pyc can be decompiled, doing this adds a bit of difficulty. Usually, after the startup configuration files are compiled, the source is not removed β this is for debugging at deployment time.
3. Node
- Commit the yarn.lock file, and use
--frozen-lockfilein production to lock dependencies
| |
package.json is used to specify version ranges, while yarn.lock locks exact versions.
With yarn install, if a dependency version in package.json conflicts with yarn.lock, the yarn.lock file is updated.
--frozen-lockfile locks dependency versions and does not update the yarn.lock file; it also greatly saves installation time, avoiding getting stuck at Building fresh packages. Note, however, that you should check whether the file links in yarn.lock are what you expect β for example, whether they use the internal registry.
- ESOCKETTIMEDOUT when installing dependency packages
| |
Or
| |
This changes the timeout from the default 30s to 300s.
Another account is that a slow disk causes dependency installation to time out, so you can try upgrading it.
4. Makefile
-jenables multi-threaded builds
| |
-j uses the same number of threads as CPU cores by default; you can use -j 4 to specify the thread count.
Although parallel builds are more efficient, dependencies can cause the build to fail, and troubleshooting becomes more complex as well.
5. Platform Side
- Docker cannot pull the v1 image format
| |
If your Docker version is older than 19.03, you can set "disable-legacy-registry":true in /etc/docker/daemon.json and restart Docker. Alternatively, add the --disable-legacy-registry flag to the Docker Client command when pulling.
The reason is that the v1 image format has been deprecated, and newer Docker versions no longer support it.
- Using buildx
Using buildx makes better use of the cache. But Docker does not install buildx by default, so it must be installed manually.
For Linux systems, first download the corresponding binary from the buildx release page https://github.com/docker/buildx/releases , then rename the binary to docker-buildx and place it in the $HOME/.docker/cli-plugins directory.
