[PR #283] [MERGED] Container volumes sometimes reused even if configured not to #1401

Closed
opened 2026-03-01 21:51:01 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/nektos/act/pull/283
Author: @N2D4
Created: 6/18/2020
Status: Merged
Merged: 6/18/2020
Merged by: @cplee

Base: masterHead: master


📝 Commits (1)

  • 9ea4e93 Fix container volumes being reused sometimes

📊 Changes

4 files changed (+33 additions, -10 deletions)

View changed files

📝 pkg/container/docker_volume.go (+24 -2)
📝 pkg/runner/expression_test.go (+2 -3)
📝 pkg/runner/run_context.go (+3 -1)
📝 pkg/runner/run_context_test.go (+4 -4)

📄 Description

This can occur even without the -r flag, but it's easier to reproduce like this.
.github/workflows/workflow.yaml:

name: Example workflow

on: push

jobs:
  example:
    name: Example job
    runs-on: ubuntu-latest

    steps:
      - run: echo "Hello" >> file.txt
      - run: echo "World!" >> file.txt
      - run: cat file.txt

Now we run:

$ act -j example -r
...
| Hello
| World!
...

This is expected.

$ act -j example -r
...
| Hello
| World!
| Hello
| World!
...

This is also expected, as the -r flag means that the containers should be re-used; in other words, file.txt contains the original content from the last run, plus the new content from this run.

$ act -j example
...
| Hello
| World!
| Hello
| World!
| Hello
| World!
...

This is unexpected; the -r flag is no longer used, but the file system wasn't reset.

$ act -j example
...
| Hello
| World!
...

This is expected; after the run without -r, the volume was deleted from disk and this time we have a clean file system.

The same thing happens even when not using -r if the container clean-up doesn't run (eg. when act is terminated in the middle of a build); the file system will persist. In the code, there's a safeguard which performs an additional clean-up before every build, but this safeguard only removes the container itself, not the volume associated with it (which is not anonymous). This PR fixes that by calling runContext.stopJobContainer(...) instead of container.Remove() before the build, which removes both the container and the volume.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/nektos/act/pull/283 **Author:** [@N2D4](https://github.com/N2D4) **Created:** 6/18/2020 **Status:** ✅ Merged **Merged:** 6/18/2020 **Merged by:** [@cplee](https://github.com/cplee) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (1) - [`9ea4e93`](https://github.com/nektos/act/commit/9ea4e93a442e89adb259d8c2340ad870cc84afd3) Fix container volumes being reused sometimes ### 📊 Changes **4 files changed** (+33 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `pkg/container/docker_volume.go` (+24 -2) 📝 `pkg/runner/expression_test.go` (+2 -3) 📝 `pkg/runner/run_context.go` (+3 -1) 📝 `pkg/runner/run_context_test.go` (+4 -4) </details> ### 📄 Description This can occur even without the `-r` flag, but it's easier to reproduce like this. `.github/workflows/workflow.yaml`: ```yaml name: Example workflow on: push jobs: example: name: Example job runs-on: ubuntu-latest steps: - run: echo "Hello" >> file.txt - run: echo "World!" >> file.txt - run: cat file.txt ``` Now we run: ```sh $ act -j example -r ... | Hello | World! ... ``` This is expected. ```sh $ act -j example -r ... | Hello | World! | Hello | World! ... ``` This is also expected, as the `-r` flag means that the containers should be re-used; in other words, file.txt contains the original content from the last run, plus the new content from this run. ```sh $ act -j example ... | Hello | World! | Hello | World! | Hello | World! ... ``` This is unexpected; the `-r` flag is no longer used, but the file system wasn't reset. ```sh $ act -j example ... | Hello | World! ... ``` This is expected; after the run without `-r`, the volume was deleted from disk and this time we have a clean file system. The same thing happens even when not using `-r` if the container clean-up doesn't run (eg. when `act` is terminated in the middle of a build); the file system will persist. In the code, there's a safeguard which performs an additional clean-up before every build, but this safeguard only removes the container itself, not the volume associated with it (which is not anonymous). This PR fixes that by calling `runContext.stopJobContainer(...)` instead of `container.Remove()` before the build, which removes both the container and the volume. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-01 21:51:01 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#1401
No description provided.