Don't ignore the (hidden) ignore files
Don’t forget to add appropriate ignore files…
.dockerignorewhen using Docker.gitignorewhen using git.gcloudignorewhen using Google Cloud Platform
This week, I’ve been bitten twice in not using these.
They’re hidden files and so they’re more easy to forget unfortunately.
.dockerignore
docker build ...
Without .dockerignore
Sending build context to Docker daemon 229.9MB
Because, even though Rust’s cargo creates a useful .gitignore, it doesn’t create .dockerignore and, as you as you create ./target, you’re going to take up (likely uncessary) build context space:
With .dockerignore (matching the cargo-created .gitignore):
target/
Reduces this to:
Sending build context to Docker daemon 110.1kB
It’s useful even if you’re building locally (as it’s faster) but it’s particularly useful when you’re using cloud-based build services.
.gcloudignore
In truth, I’ve not used this before but I will from hereon.
I developed a Golang Cloud Function and use the following structure:
.
├── cmd
├── firestore.png
├── function.go
├── .gcloudignore
├── .git
├── .gitignore
├── go.mod
├── go.sum
├── LICENSE
├── README.md
├── tester.json
└── .vscode
The ./cmd directory is not needed for the deployment as it’s used only for locally testing but, I also didn’t need to keep shipping the entire hidden (!) .git tree, .vscode, the PNG, README.md, LICENSE and very much not the secret (./tester.json).
So:
With ./gcloudignore:
.git/
.vscode/
cmd/
firestore.png
README.md
tester.json
That’s all!