Skip to content

Commit a3c8116

Browse files
fix: step container workdir and mounts (#93)
* fix: step container workdir and mounts * avoid perm issues and do not mount tool_cache
1 parent eddc77f commit a3c8116

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
@@ -382,13 +382,18 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string
382382

383383
binds, mounts := rc.GetBindsAndMounts()
384384
networkMode := fmt.Sprintf("container:%s", rc.jobContainerName())
385+
var workdir string
385386
if rc.IsHostEnv(ctx) {
386387
networkMode = "default"
388+
ext := container.LinuxContainerEnvironmentExtensions{}
389+
workdir = ext.ToContainerPath(rc.Config.Workdir)
390+
} else {
391+
workdir = rc.JobContainer.ToContainerPath(rc.Config.Workdir)
387392
}
388393
stepContainer := container.NewContainer(&container.NewContainerInput{
389394
Cmd: cmd,
390395
Entrypoint: entrypoint,
391-
WorkingDir: rc.JobContainer.ToContainerPath(rc.Config.Workdir),
396+
WorkingDir: workdir,
392397
Image: image,
393398
Username: rc.Config.Secrets["DOCKER_USERNAME"],
394399
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
@@ -38,6 +38,7 @@ func init() {
3838

3939
platforms = map[string]string{
4040
"ubuntu-latest": baseImage,
41+
"self-hosted": "-self-hosted",
4142
}
4243

4344
if l := os.Getenv("ACT_TEST_LOG_LEVEL"); l != "" {
@@ -325,6 +326,9 @@ func TestRunEvent(t *testing.T) {
325326

326327
// local remote action overrides
327328
{workdir, "local-remote-action-overrides", "push", "", platforms, secrets},
329+
330+
// docker action on host executor
331+
{workdir, "docker-action-host-env", "push", "", platforms, secrets},
328332
}
329333

330334
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)