Skip to content

Commit 2dea26b

Browse files
fix: step container workdir and mounts (#93) (#5295)
* fix: step container workdir and mounts * avoid perm issues and do not mount tool_cache Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent c457755 commit 2dea26b

File tree

8 files changed

+77
-2
lines changed

8 files changed

+77
-2
lines changed

pkg/runner/action.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,18 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string
408408

409409
binds, mounts := rc.GetBindsAndMounts()
410410
networkMode := fmt.Sprintf("container:%s", rc.jobContainerName())
411+
var workdir string
411412
if rc.IsHostEnv(ctx) {
412413
networkMode = "default"
414+
ext := container.LinuxContainerEnvironmentExtensions{}
415+
workdir = ext.ToContainerPath(rc.Config.Workdir)
416+
} else {
417+
workdir = rc.JobContainer.ToContainerPath(rc.Config.Workdir)
413418
}
414419
stepContainer := container.NewContainer(&container.NewContainerInput{
415420
Cmd: cmd,
416421
Entrypoint: entrypoint,
417-
WorkingDir: rc.JobContainer.ToContainerPath(rc.Config.Workdir),
422+
WorkingDir: workdir,
418423
Image: image,
419424
Username: rc.Config.Secrets["DOCKER_USERNAME"],
420425
Password: rc.Config.Secrets["DOCKER_PASSWORD"],

pkg/runner/run_context.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string) {
139139

140140
ext := container.LinuxContainerEnvironmentExtensions{}
141141

142+
if hostEnv, ok := rc.JobContainer.(*container.HostEnvironment); ok {
143+
mounts := map[string]string{}
144+
// Permission issues?
145+
// binds = append(binds, hostEnv.ToolCache+":/opt/hostedtoolcache")
146+
binds = append(binds, hostEnv.GetActPath()+":"+ext.GetActPath())
147+
binds = append(binds, hostEnv.ToContainerPath(rc.Config.Workdir)+":"+ext.ToContainerPath(rc.Config.Workdir))
148+
return binds, mounts
149+
}
142150
mounts := map[string]string{
143151
"act-toolcache": "/opt/hostedtoolcache",
144152
name + "-env": ext.GetActPath(),

pkg/runner/runner_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func init() {
3939

4040
platforms = map[string]string{
4141
"ubuntu-latest": baseImage,
42+
"self-hosted": "-self-hosted",
4243
}
4344

4445
if l := os.Getenv("ACT_TEST_LOG_LEVEL"); l != "" {
@@ -330,6 +331,9 @@ func TestRunEvent(t *testing.T) {
330331

331332
// local remote action overrides
332333
{workdir, "local-remote-action-overrides", "push", "", platforms, secrets},
334+
335+
// docker action on host executor
336+
{workdir, "docker-action-host-env", "push", "", platforms, secrets},
333337
}
334338

335339
for _, table := range tables {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM debian:bullseye-slim
2+
3+
# Install dependencies
4+
RUN apt-get update && apt-get install -y \
5+
curl \
6+
&& apt-get clean
7+
8+
# Copy the entrypoint script
9+
COPY entrypoint.sh /entrypoint.sh
10+
RUN chmod +x /entrypoint.sh
11+
12+
# Set the entrypoint
13+
ENTRYPOINT ["/entrypoint.sh"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: "Hello World Docker Action"
2+
description: "A simple Docker action that prints Hello, World! and environment variables."
3+
inputs:
4+
who-to-greet:
5+
description: "Who to greet"
6+
required: false
7+
default: "World"
8+
runs:
9+
using: "docker"
10+
image: "Dockerfile"
11+
args:
12+
- ${{ inputs.who-to-greet }}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Print a greeting
5+
echo "Hello, $1!"
6+
7+
# Print all environment variables
8+
echo "Environment Variables:"
9+
env
10+
11+
ls -la "$PWD"
12+
ls -la "$PWD/docker-action-host-env"
13+
14+
if [ -f "$PWD/docker-action-host-env/Dockerfile" ]; then
15+
echo "Dockerfile exists in workspace."
16+
else
17+
echo "Dockerfile does not exist in workspace."
18+
fi
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Hello World Docker Action Workflow
2+
3+
on: [push]
4+
5+
jobs:
6+
hello_world_job:
7+
runs-on: self-hosted
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v4
11+
12+
- name: Run Hello World Docker Action
13+
uses: ./docker-action-host-env/action
14+
with:
15+
who-to-greet: "GitHub"

pkg/runner/testdata/uses-nested-composite/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: uses-docker-url
1+
name: uses-nested-composite
22
on: push
33

44
jobs:

0 commit comments

Comments
 (0)