fix: step container workdir and mounts (#93)

* fix: step container workdir and mounts
* avoid perm issues and do not mount tool_cache
This commit is contained in:
ChristopherHX
2025-04-26 14:14:52 +02:00
committed by GitHub
parent eddc77f3e0
commit a3c8116dee
8 changed files with 77 additions and 2 deletions

View File

@@ -382,13 +382,18 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string
binds, mounts := rc.GetBindsAndMounts()
networkMode := fmt.Sprintf("container:%s", rc.jobContainerName())
var workdir string
if rc.IsHostEnv(ctx) {
networkMode = "default"
ext := container.LinuxContainerEnvironmentExtensions{}
workdir = ext.ToContainerPath(rc.Config.Workdir)
} else {
workdir = rc.JobContainer.ToContainerPath(rc.Config.Workdir)
}
stepContainer := container.NewContainer(&container.NewContainerInput{
Cmd: cmd,
Entrypoint: entrypoint,
WorkingDir: rc.JobContainer.ToContainerPath(rc.Config.Workdir),
WorkingDir: workdir,
Image: image,
Username: rc.Config.Secrets["DOCKER_USERNAME"],
Password: rc.Config.Secrets["DOCKER_PASSWORD"],

View File

@@ -139,6 +139,14 @@ func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string) {
ext := container.LinuxContainerEnvironmentExtensions{}
if hostEnv, ok := rc.JobContainer.(*container.HostEnvironment); ok {
mounts := map[string]string{}
// Permission issues?
// binds = append(binds, hostEnv.ToolCache+":/opt/hostedtoolcache")
binds = append(binds, hostEnv.GetActPath()+":"+ext.GetActPath())
binds = append(binds, hostEnv.ToContainerPath(rc.Config.Workdir)+":"+ext.ToContainerPath(rc.Config.Workdir))
return binds, mounts
}
mounts := map[string]string{
"act-toolcache": "/opt/hostedtoolcache",
name + "-env": ext.GetActPath(),

View File

@@ -38,6 +38,7 @@ func init() {
platforms = map[string]string{
"ubuntu-latest": baseImage,
"self-hosted": "-self-hosted",
}
if l := os.Getenv("ACT_TEST_LOG_LEVEL"); l != "" {
@@ -325,6 +326,9 @@ func TestRunEvent(t *testing.T) {
// local remote action overrides
{workdir, "local-remote-action-overrides", "push", "", platforms, secrets},
// docker action on host executor
{workdir, "docker-action-host-env", "push", "", platforms, secrets},
}
for _, table := range tables {

View File

@@ -0,0 +1,13 @@
FROM debian:bullseye-slim
# Install dependencies
RUN apt-get update && apt-get install -y \
curl \
&& apt-get clean
# Copy the entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Set the entrypoint
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -0,0 +1,12 @@
name: "Hello World Docker Action"
description: "A simple Docker action that prints Hello, World! and environment variables."
inputs:
who-to-greet:
description: "Who to greet"
required: false
default: "World"
runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.who-to-greet }}

View File

@@ -0,0 +1,18 @@
#!/bin/bash
set -e
# Print a greeting
echo "Hello, $1!"
# Print all environment variables
echo "Environment Variables:"
env
ls -la "$PWD"
ls -la "$PWD/docker-action-host-env"
if [ -f "$PWD/docker-action-host-env/Dockerfile" ]; then
echo "Dockerfile exists in workspace."
else
echo "Dockerfile does not exist in workspace."
fi

View File

@@ -0,0 +1,15 @@
name: Hello World Docker Action Workflow
on: [push]
jobs:
hello_world_job:
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Hello World Docker Action
uses: ./docker-action-host-env/action
with:
who-to-greet: "GitHub"

View File

@@ -1,4 +1,4 @@
name: uses-docker-url
name: uses-nested-composite
on: push
jobs: