29 Commits

Author SHA1 Message Date
3585119c37 Fix passing multiple values through --container-options
All checks were successful
continuous-integration/drone/push Build is passing
2024-04-18 09:33:53 +02:00
65cddc2ed7 Allow KVM access on request
All checks were successful
continuous-integration/drone/push Build is passing
2024-04-18 09:18:40 +02:00
3a7b0940d8 Third try for pull false
All checks were successful
continuous-integration/drone/push Build is passing
2024-04-17 19:02:21 +02:00
d4adfe002c Second try passing pull as false
All checks were successful
continuous-integration/drone/push Build is passing
2024-04-17 18:58:38 +02:00
5fa92cf781 Fix broken passing of negative --pull
All checks were successful
continuous-integration/drone/push Build is passing
2024-04-17 18:48:15 +02:00
eb6ccfbe0e Upgrade to golang 1.21
All checks were successful
continuous-integration/drone/push Build is passing
2024-04-16 19:28:09 +02:00
35ce32a4ed Fix patch missing LF
Some checks failed
continuous-integration/drone/push Build is failing
2024-04-16 19:26:39 +02:00
9beebfaca9 Fix patch
Some checks failed
continuous-integration/drone/push Build is failing
2024-04-16 19:24:55 +02:00
d6a684c400 Fixed no_force_pull
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is failing
2023-08-22 17:31:08 +02:00
6698f5978a Optionally no pulling using NoForcePull
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-22 17:25:33 +02:00
923123169b Fix container ID detection also in cgroup v2
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-22 16:31:36 +02:00
28a1de08ab Fix container Id detection from cgroup as "12:rdma:/" is possible
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-31 19:03:21 +02:00
946603e2f4 Use latest that includes fix https://github.com/nektos/act/pull/1928
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-31 15:34:26 +02:00
2c52eb7b7e Downgrade act to 0.2.41 to avoid "failed to attach to exec: http: invalid Host header" (https://gitea.com/gitea/act_runner/issues/293)
Some checks failed
continuous-integration/drone/push Build is failing
2023-07-31 15:27:02 +02:00
2a5ba3bc21 FIX imported and not used after patch is applied
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-31 15:01:45 +02:00
e21a44878d Fix act source code patching
Some checks failed
continuous-integration/drone/push Build is failing
2023-07-31 14:49:34 +02:00
034c040f8b FIX remove act glibc dependency
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-31 14:04:00 +02:00
750431982f Fix missing patch executable
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-31 12:24:55 +02:00
7bae512b01 Patch act to not bind the workdir as we do it using --container-options
Some checks failed
continuous-integration/drone/push Build is failing
2023-07-31 12:21:39 +02:00
c8c002ab01 Avoid error forbidden path outside the build context: ../act/bin/act
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-31 12:09:54 +02:00
60c0747e24 Compile the act ourselves.
Some checks failed
continuous-integration/drone/push Build is failing
2023-07-31 12:04:59 +02:00
9a8b298ac9 Try to bind working dir so deduplication resolves conflict with container-options
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-28 22:02:00 +02:00
5de3d0579f Test if docker API 1.25 has Mounts. Upgrade act so that --container-options is supported
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-28 20:58:49 +02:00
faacf7d664 Use higher docker API version to get mounts
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-28 20:28:59 +02:00
0714b97213 Debug getting mount points
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-28 20:18:18 +02:00
b9f6b37d1e Debug search for working directory bind
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-28 19:57:33 +02:00
c5c6dcde21 Must use symlink for hidden docker socket otherwise "invalid cross-device link"
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-28 19:48:20 +02:00
32246a5328 Link hidden docker socket to the expected path
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-28 19:38:52 +02:00
836c1329fa Alow not a DinD mode of operation
All checks were successful
continuous-integration/drone Build is passing
2023-07-28 18:24:39 +02:00
8 changed files with 288 additions and 50 deletions

View File

@@ -1,31 +1,32 @@
kind: pipeline
type: vm
name: default
platform:
os: linux
arch: amd64
pool:
use: ubuntu
steps:
- name: act
image: golang:1.21
commands:
- git clone https://github.com/nektos/act.git && cd act
- export ACT_VERSION=$(git describe --tags --dirty --always | sed -e 's/^v//')
- git apply ../patches/001-workdir-bind.patch
- mkdir bin
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$ACT_VERSION" -o bin/act main.go
- name: build
image: golang:1.19
image: golang:1.21
commands:
- go test ./...
- sh scripts/build.sh
- name: publish
- name: docker
image: plugins/docker
pull: if-not-exists
settings:
repo: plugins/github-actions
auto_tag: true
dockerfile: docker/Dockerfile.linux.amd64
registry: https://git.ivasoft.cz
username:
from_secret: docker_username
from_secret: repo_user
password:
from_secret: docker_password
when:
event:
- tag
from_secret: repo_pass
repo: git.ivasoft.cz/sw/github-actions
dockerfile: docker/Dockerfile.linux.amd64
tags:
- latest
- ${DRONE_TAG:-latest}

View File

@@ -76,6 +76,16 @@ func main() {
Value: "node:16-buster-slim",
EnvVar: "PLUGIN_ACTION_IMAGE",
},
cli.BoolFlag{
Name: "no-force-pull",
Usage: "disable forced pulling in act",
EnvVar: "PLUGIN_NO_FORCE_PULL",
},
cli.BoolFlag{
Name: "kvm",
Usage: "enable KVM (Kernel Virtual Machine)",
EnvVar: "PLUGIN_KVM",
},
cli.StringFlag{
Name: "event-payload",
Usage: "Webhook event payload",
@@ -155,6 +165,11 @@ func main() {
Usage: "don't start the docker daemon",
EnvVar: "PLUGIN_DAEMON_OFF",
},
cli.BoolFlag{
Name: "not.hidden.socket",
Usage: "in case of daemon.off use unix:///run/hidden_docker.sock instead of unix:///run/docker.sock",
EnvVar: "PLUGIN_NOT_HIDDEN_SOCKET",
},
}
if err := app.Run(os.Args); err != nil {
@@ -183,23 +198,26 @@ func run(c *cli.Context) error {
Env: actionEnv,
Verbose: c.Bool("action-verbose"),
Image: c.String("action-image"),
NoForcePull: c.Bool("no-force-pull"),
Kvm: c.Bool("kvm"),
EventPayload: c.String("event-payload"),
Actor: c.String("actor"),
},
Daemon: daemon.Daemon{
Registry: c.String("docker.registry"),
Mirror: c.String("daemon.mirror"),
StorageDriver: c.String("daemon.storage-driver"),
StoragePath: c.String("daemon.storage-path"),
Insecure: c.Bool("daemon.insecure"),
Disabled: c.Bool("daemon.off"),
IPv6: c.Bool("daemon.ipv6"),
Debug: c.Bool("daemon.debug"),
Bip: c.String("daemon.bip"),
DNS: c.StringSlice("daemon.dns"),
DNSSearch: c.StringSlice("daemon.dns-search"),
MTU: c.String("daemon.mtu"),
Experimental: c.Bool("daemon.experimental"),
Registry: c.String("docker.registry"),
Mirror: c.String("daemon.mirror"),
StorageDriver: c.String("daemon.storage-driver"),
StoragePath: c.String("daemon.storage-path"),
Insecure: c.Bool("daemon.insecure"),
Disabled: c.Bool("daemon.off"),
IPv6: c.Bool("daemon.ipv6"),
Debug: c.Bool("daemon.debug"),
Bip: c.String("daemon.bip"),
DNS: c.StringSlice("daemon.dns"),
DNSSearch: c.StringSlice("daemon.dns-search"),
MTU: c.String("daemon.mtu"),
Experimental: c.Bool("daemon.experimental"),
NotHiddenSocket: c.Bool("not.hidden.socket"),
},
}
return plugin.Exec()

View File

@@ -4,6 +4,14 @@ import (
"fmt"
"os/exec"
"time"
"github.com/pkg/errors"
"os"
)
const (
StdDockerSocketPath = "/var/run/docker.sock"
HiddenDockerSocketPath = "/var/run/hidden_docker.sock"
)
type Daemon struct {
@@ -20,11 +28,16 @@ type Daemon struct {
MTU string // Docker daemon mtu setting
IPv6 bool // Docker daemon IPv6 networking
Experimental bool // Docker daemon enable experimental mode
NotHiddenSocket bool // Docker daemon does listen on standard socket /var/run/docker.sock
}
func StartDaemon(d Daemon) error {
if !d.Disabled {
startDaemon(d)
} else if !d.NotHiddenSocket {
if err := os.Symlink(HiddenDockerSocketPath, StdDockerSocketPath); err != nil {
return errors.Wrap(err, "failed to link hidden docker socket to common one")
}
}
return waitForDaemon()
}

View File

@@ -3,7 +3,7 @@ FROM docker:dind
ENV DOCKER_HOST=unix:///var/run/docker.sock
RUN apk add --no-cache ca-certificates curl
RUN curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | sh -s v0.2.34
ADD act/bin/act /bin/
ADD release/linux/amd64/plugin /bin/
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/plugin"]

19
go.mod
View File

@@ -4,8 +4,10 @@ go 1.19
require (
github.com/buildkite/yaml v2.1.0+incompatible
github.com/docker/docker v24.0.5+incompatible
github.com/ghodss/yaml v1.0.0
github.com/joho/godotenv v1.4.0
github.com/opencontainers/selinux v1.11.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
github.com/urfave/cli v1.22.10
@@ -13,8 +15,21 @@ require (
)
require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.6.0 // indirect
gotest.tools/v3 v3.5.0 // indirect
)

84
go.sum
View File

@@ -1,50 +1,102 @@
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/buildkite/yaml v2.1.0+incompatible h1:xirI+ql5GzfikVNDmt+yeiXpf/v1Gt03qXTtT5WXdr8=
github.com/buildkite/yaml v2.1.0+incompatible/go.mod h1:UoU8vbcwu1+vjZq01+KrpSeLBgQQIjL/H7Y6KwikUrI=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v24.0.5+incompatible h1:WmgcE4fxyI6EEXxBRxsHnZXrO1pQ3smi0k/jho4HLeY=
github.com/docker/docker v24.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU=
github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.10 h1:p8Fspmz3iTctJstry1PYS3HVdllxnEzTEsgIgtxTrCk=
github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY=
gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=

View File

@@ -0,0 +1,34 @@
--- "a/pkg/runner/run_context.go"
+++ "b/pkg/runner/run_context.go"
@@ -14,7 +14,6 @@
"os"
"path/filepath"
"regexp"
- "runtime"
"strings"
"github.com/docker/go-connections/nat"
@@ -22,7 +21,6 @@
"github.com/nektos/act/pkg/container"
"github.com/nektos/act/pkg/exprparser"
"github.com/nektos/act/pkg/model"
- "github.com/opencontainers/selinux/go-selinux"
)
// RunContext contains info about current job
@@ -155,14 +153,7 @@
}
if rc.Config.BindWorkdir {
- bindModifiers := ""
- if runtime.GOOS == "darwin" {
- bindModifiers = ":delegated"
- }
- if selinux.GetEnabled() {
- bindModifiers = ":z"
- }
- binds = append(binds, fmt.Sprintf("%s:%s%s", rc.Config.Workdir, ext.ToContainerPath(rc.Config.Workdir), bindModifiers))
+ // Bind done using --container-options command-line option
} else {
mounts[name] = ext.ToContainerPath(rc.Config.Workdir)
}

105
plugin.go
View File

@@ -1,15 +1,21 @@
package plugin
import (
"bufio"
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"runtime"
"strings"
"github.com/drone-plugins/drone-github-actions/daemon"
"github.com/drone-plugins/drone-github-actions/utils"
"github.com/pkg/errors"
docker "github.com/docker/docker/client"
"github.com/opencontainers/selinux/go-selinux"
)
const (
@@ -32,6 +38,8 @@ type (
EventPayload string // Webhook event payload
Actor string
Verbose bool
NoForcePull bool
Kvm bool
}
Plugin struct {
@@ -86,6 +94,34 @@ func (p Plugin) Exec() error {
cmdArgs = append(cmdArgs, "-v")
}
if p.Action.NoForcePull {
cmdArgs = append(cmdArgs, "--pull=false")
}
if p.Action.Kvm {
cmdArgs = append(cmdArgs, "--privileged")
}
if p.Daemon.Disabled {
hostWorkDirPath, guestWorkDirPath, err := getWorkDirPath(p, context.Background())
if err != nil {
return errors.Wrap(err, "failed to locate working directory on the host. You may use DinD instead by disabling daemon_off.")
}
bindModifiers := ""
if runtime.GOOS == "darwin" {
bindModifiers = ":delegated"
}
if selinux.GetEnabled() {
bindModifiers = ":z"
}
opt := fmt.Sprintf("--volume=%s:%s%s", hostWorkDirPath, guestWorkDirPath, bindModifiers)
if p.Action.Kvm {
opt = opt + " --volume=/dev/kvm:/dev/kvm"
}
cmdArgs = append(cmdArgs, "--container-options", opt)
}
cmd := exec.Command("act", cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
@@ -103,3 +139,72 @@ func (p Plugin) Exec() error {
func trace(cmd *exec.Cmd) {
fmt.Fprintf(os.Stdout, "+ %s\n", strings.Join(cmd.Args, " "))
}
func getWorkDirPath(p Plugin, ctx context.Context) (string, string, error) {
// Connect to the docker
docker, err := docker.NewClient("unix://"+daemon.StdDockerSocketPath, "v1.25", nil, nil)
if err != nil {
return "", "", errors.Wrap(err, "failed to create docker client")
}
defer docker.Close()
// Determine our container identifier
cntrId, err := getContainerId()
if err != nil {
return "", "", errors.Wrap(err, "failed to get our container id")
}
// Find the proper mount
cwd, err := os.Getwd()
if err != nil {
return "", "", errors.Wrap(err, "failed to locate the working directory in the container")
}
cntr, err := docker.ContainerInspect(ctx, cntrId)
if err != nil {
return "", "", errors.Wrap(err, "failed to inspect ourselves as a container")
}
for _, i := range cntr.Mounts {
if i.Destination == cwd {
return i.Source, i.Destination, nil
}
}
return "", "", errors.New("mount point with working directory not found")
}
func getContainerId() (string, error) {
file, err := os.Open("/proc/self/mountinfo")
if err != nil {
return "", err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
// The file name is the container identifier
// Example: 467 457 0:33 /var/lib/docker/containers/3005e3555a74d3196ea35c5a1ae54fe35a49d55102299208df8dc275b5e9309c/hostname /etc/hostname rw,noatime - btrfs /dev/sda3 rw,space_cache=v2,subvolid=5,subvol=/
// Example: 700 678 8:3 /var/lib/docker/containers/d012398a817e7c659f892bfdda00dd2a416a0443da0b31a4c86567ae4b77a6a7/hostname /etc/hostname rw,noatime - ext4 /dev/sda3 rw,noacl
line := scanner.Text()
const prefix = "/docker/containers/"
pathOffset := strings.Index(line, prefix)
if pathOffset == -1 {
continue
}
postPrefix := line[pathOffset+len(prefix):]
endOffset := strings.Index(postPrefix, "/")
if endOffset == -1 {
continue
}
result := postPrefix[:endOffset]
if result == "" {
continue
}
return result, nil
}
return "", errors.New("no suitable cgroup entry found")
}