Skip to content

Commit ef34406

Browse files
committed
ci: add swap and container memory limits to prevent OOM
- Recreate swap with 4GB to provide memory headroom - Set GOGC=30 and GOMAXPROCS=2 to reduce Go memory pressure - Add BAKE_CONTAINER_MEMORY env var support to limit test container memory (512MB each), preventing them from starving the test process
1 parent 4e18b32 commit ef34406

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ jobs:
1616
run: docker buildx install
1717
shell: bash
1818

19+
- name: Create swap
20+
run: |
21+
sudo swapoff -a || true
22+
sudo rm -f /swapfile
23+
sudo fallocate -l 4G /swapfile
24+
sudo chmod 600 /swapfile
25+
sudo mkswap /swapfile
26+
sudo swapon /swapfile
27+
shell: bash
28+
1929
- name: Build local image
2030
run: docker build -f Dockerfile -t ghcr.io/beatlabs/bake:latest .
2131
shell: bash
2232

2333
- name: Bake CI
24-
run: ./bake.sh ci
34+
run: ./bake.sh --env GOGC=30 --env GOMAXPROCS=2 --env BAKE_CONTAINER_MEMORY=536870912 ci
2535
env:
2636
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2737

docker/simplecomponent.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,14 @@ func (c *SimpleComponent) runContainer(session *Session, conf SimpleContainerCon
145145
}
146146

147147
publishPorts, _ := strconv.ParseBool(os.Getenv("BAKE_PUBLISH_PORTS"))
148-
hcOpts := func(hc *docker.HostConfig) { hc.PublishAllPorts = publishPorts }
148+
hcOpts := func(hc *docker.HostConfig) {
149+
hc.PublishAllPorts = publishPorts
150+
if memLimit := os.Getenv("BAKE_CONTAINER_MEMORY"); memLimit != "" {
151+
if v, err := strconv.ParseInt(memLimit, 10, 64); err == nil {
152+
hc.Memory = v
153+
}
154+
}
155+
}
149156
resource, err := pool.RunWithOptions(runOpts, hcOpts)
150157
if err != nil {
151158
return fmt.Errorf("run %s: %w", fullContainerName, err)

0 commit comments

Comments
 (0)