mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-03-20 03:46:09 +08:00
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:
@@ -382,13 +382,18 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string
|
|||||||
|
|
||||||
binds, mounts := rc.GetBindsAndMounts()
|
binds, mounts := rc.GetBindsAndMounts()
|
||||||
networkMode := fmt.Sprintf("container:%s", rc.jobContainerName())
|
networkMode := fmt.Sprintf("container:%s", rc.jobContainerName())
|
||||||
|
var workdir string
|
||||||
if rc.IsHostEnv(ctx) {
|
if rc.IsHostEnv(ctx) {
|
||||||
networkMode = "default"
|
networkMode = "default"
|
||||||
|
ext := container.LinuxContainerEnvironmentExtensions{}
|
||||||
|
workdir = ext.ToContainerPath(rc.Config.Workdir)
|
||||||
|
} else {
|
||||||
|
workdir = rc.JobContainer.ToContainerPath(rc.Config.Workdir)
|
||||||
}
|
}
|
||||||
stepContainer := container.NewContainer(&container.NewContainerInput{
|
stepContainer := container.NewContainer(&container.NewContainerInput{
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
Entrypoint: entrypoint,
|
Entrypoint: entrypoint,
|
||||||
WorkingDir: rc.JobContainer.ToContainerPath(rc.Config.Workdir),
|
WorkingDir: workdir,
|
||||||
Image: image,
|
Image: image,
|
||||||
Username: rc.Config.Secrets["DOCKER_USERNAME"],
|
Username: rc.Config.Secrets["DOCKER_USERNAME"],
|
||||||
Password: rc.Config.Secrets["DOCKER_PASSWORD"],
|
Password: rc.Config.Secrets["DOCKER_PASSWORD"],
|
||||||
|
|||||||
@@ -139,6 +139,14 @@ func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string) {
|
|||||||
|
|
||||||
ext := container.LinuxContainerEnvironmentExtensions{}
|
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{
|
mounts := map[string]string{
|
||||||
"act-toolcache": "/opt/hostedtoolcache",
|
"act-toolcache": "/opt/hostedtoolcache",
|
||||||
name + "-env": ext.GetActPath(),
|
name + "-env": ext.GetActPath(),
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ func init() {
|
|||||||
|
|
||||||
platforms = map[string]string{
|
platforms = map[string]string{
|
||||||
"ubuntu-latest": baseImage,
|
"ubuntu-latest": baseImage,
|
||||||
|
"self-hosted": "-self-hosted",
|
||||||
}
|
}
|
||||||
|
|
||||||
if l := os.Getenv("ACT_TEST_LOG_LEVEL"); l != "" {
|
if l := os.Getenv("ACT_TEST_LOG_LEVEL"); l != "" {
|
||||||
@@ -325,6 +326,9 @@ func TestRunEvent(t *testing.T) {
|
|||||||
|
|
||||||
// local remote action overrides
|
// local remote action overrides
|
||||||
{workdir, "local-remote-action-overrides", "push", "", platforms, secrets},
|
{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 {
|
for _, table := range tables {
|
||||||
|
|||||||
13
pkg/runner/testdata/docker-action-host-env/action/Dockerfile
vendored
Normal file
13
pkg/runner/testdata/docker-action-host-env/action/Dockerfile
vendored
Normal 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"]
|
||||||
12
pkg/runner/testdata/docker-action-host-env/action/action.yml
vendored
Normal file
12
pkg/runner/testdata/docker-action-host-env/action/action.yml
vendored
Normal 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 }}
|
||||||
18
pkg/runner/testdata/docker-action-host-env/action/entrypoint.sh
vendored
Normal file
18
pkg/runner/testdata/docker-action-host-env/action/entrypoint.sh
vendored
Normal 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
|
||||||
15
pkg/runner/testdata/docker-action-host-env/push.yml
vendored
Normal file
15
pkg/runner/testdata/docker-action-host-env/push.yml
vendored
Normal 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"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: uses-docker-url
|
name: uses-nested-composite
|
||||||
on: push
|
on: push
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|||||||
Reference in New Issue
Block a user