mirror of
https://gitea.com/gitea/act_runner.git
synced 2025-12-18 12:04:47 +00:00
Compare commits
1 Commits
53f8bbc42f
...
lunny/upgr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df97923656 |
@@ -66,7 +66,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
target: basic
|
|
||||||
platforms: |
|
platforms: |
|
||||||
linux/amd64
|
linux/amd64
|
||||||
linux/arm64
|
linux/arm64
|
||||||
@@ -74,25 +73,13 @@ jobs:
|
|||||||
tags: |
|
tags: |
|
||||||
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }}
|
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }}
|
||||||
|
|
||||||
- name: Build and push dind
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: ./Dockerfile
|
|
||||||
target: dind
|
|
||||||
platforms: |
|
|
||||||
linux/amd64
|
|
||||||
linux/arm64
|
|
||||||
push: true
|
|
||||||
tags: |
|
|
||||||
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }}-dind
|
|
||||||
|
|
||||||
- name: Build and push dind-rootless
|
- name: Build and push dind-rootless
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
|
env:
|
||||||
|
ACTIONS_RUNTIME_TOKEN: "" # See https://gitea.com/gitea/act_runner/issues/119
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile.rootless
|
||||||
target: dind-rootless
|
|
||||||
platforms: |
|
platforms: |
|
||||||
linux/amd64
|
linux/amd64
|
||||||
linux/arm64
|
linux/arm64
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
target: basic
|
|
||||||
platforms: |
|
platforms: |
|
||||||
linux/amd64
|
linux/amd64
|
||||||
linux/arm64
|
linux/arm64
|
||||||
@@ -82,26 +81,13 @@ jobs:
|
|||||||
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}
|
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}
|
||||||
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }}
|
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }}
|
||||||
|
|
||||||
- name: Build and push dind
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: ./Dockerfile
|
|
||||||
target: dind
|
|
||||||
platforms: |
|
|
||||||
linux/amd64
|
|
||||||
linux/arm64
|
|
||||||
push: true
|
|
||||||
tags: |
|
|
||||||
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}-dind
|
|
||||||
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }}-dind
|
|
||||||
|
|
||||||
- name: Build and push dind-rootless
|
- name: Build and push dind-rootless
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
|
env:
|
||||||
|
ACTIONS_RUNTIME_TOKEN: "" # See https://gitea.com/gitea/act_runner/issues/119
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile.rootless
|
||||||
target: dind-rootless
|
|
||||||
platforms: |
|
platforms: |
|
||||||
linux/amd64
|
linux/amd64
|
||||||
linux/arm64
|
linux/arm64
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,4 @@
|
|||||||
/act_runner
|
act_runner
|
||||||
.env
|
.env
|
||||||
.runner
|
.runner
|
||||||
coverage.txt
|
coverage.txt
|
||||||
|
|||||||
46
Dockerfile
46
Dockerfile
@@ -1,54 +1,16 @@
|
|||||||
FROM golang:1.23-alpine AS builder
|
FROM golang:1.23-alpine AS builder
|
||||||
|
|
||||||
# Do not remove `git` here, it is required for getting runner version when executing `make build`
|
# Do not remove `git` here, it is required for getting runner version when executing `make build`
|
||||||
RUN apk add --no-cache make git
|
RUN apk add --no-cache make git
|
||||||
|
|
||||||
ARG GOPROXY
|
|
||||||
ENV GOPROXY=${GOPROXY:-}
|
|
||||||
|
|
||||||
COPY . /opt/src/act_runner
|
COPY . /opt/src/act_runner
|
||||||
WORKDIR /opt/src/act_runner
|
WORKDIR /opt/src/act_runner
|
||||||
|
|
||||||
RUN make clean && make build
|
RUN make clean && make build
|
||||||
|
|
||||||
FROM docker:dind AS dind
|
FROM alpine
|
||||||
|
RUN apk add --no-cache git bash tini
|
||||||
RUN apk add --no-cache s6 bash git
|
|
||||||
|
|
||||||
COPY --from=builder /opt/src/act_runner/act_runner /usr/local/bin/act_runner
|
COPY --from=builder /opt/src/act_runner/act_runner /usr/local/bin/act_runner
|
||||||
COPY scripts/run.sh /usr/local/bin/run.sh
|
COPY scripts/run.sh /opt/act/run.sh
|
||||||
COPY scripts/s6 /etc/s6
|
|
||||||
|
|
||||||
VOLUME /data
|
ENTRYPOINT ["/sbin/tini","--","/opt/act/run.sh"]
|
||||||
|
|
||||||
ENTRYPOINT ["s6-svscan","/etc/s6"]
|
|
||||||
|
|
||||||
FROM docker:dind-rootless AS dind-rootless
|
|
||||||
|
|
||||||
USER root
|
|
||||||
RUN apk add --no-cache s6 bash git
|
|
||||||
|
|
||||||
COPY --from=builder /opt/src/act_runner/act_runner /usr/local/bin/act_runner
|
|
||||||
COPY scripts/run.sh /usr/local/bin/run.sh
|
|
||||||
COPY scripts/s6 /etc/s6
|
|
||||||
|
|
||||||
VOLUME /data
|
|
||||||
|
|
||||||
RUN mkdir -p /data && chown -R rootless:rootless /etc/s6 /data
|
|
||||||
|
|
||||||
ENV DOCKER_HOST=unix:///run/user/1000/docker.sock
|
|
||||||
|
|
||||||
USER rootless
|
|
||||||
ENTRYPOINT ["s6-svscan","/etc/s6"]
|
|
||||||
|
|
||||||
FROM alpine AS basic
|
|
||||||
RUN apk add --no-cache tini bash git
|
|
||||||
|
|
||||||
COPY --from=builder /opt/src/act_runner/act_runner /usr/local/bin/act_runner
|
|
||||||
COPY scripts/run.sh /usr/local/bin/run.sh
|
|
||||||
|
|
||||||
VOLUME /var/run/docker.sock
|
|
||||||
|
|
||||||
VOLUME /data
|
|
||||||
|
|
||||||
ENTRYPOINT ["/sbin/tini","--","run.sh"]
|
|
||||||
|
|||||||
24
Dockerfile.rootless
Normal file
24
Dockerfile.rootless
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
FROM golang:1.23-alpine AS builder
|
||||||
|
# Do not remove `git` here, it is required for getting runner version when executing `make build`
|
||||||
|
RUN apk add --no-cache make git
|
||||||
|
|
||||||
|
COPY . /opt/src/act_runner
|
||||||
|
WORKDIR /opt/src/act_runner
|
||||||
|
|
||||||
|
RUN make clean && make build
|
||||||
|
|
||||||
|
FROM docker:dind-rootless
|
||||||
|
USER root
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
git bash supervisor
|
||||||
|
|
||||||
|
COPY --from=builder /opt/src/act_runner/act_runner /usr/local/bin/act_runner
|
||||||
|
COPY /scripts/supervisord.conf /etc/supervisord.conf
|
||||||
|
COPY /scripts/run.sh /opt/act/run.sh
|
||||||
|
COPY /scripts/rootless.sh /opt/act/rootless.sh
|
||||||
|
|
||||||
|
RUN mkdir /data \
|
||||||
|
&& chown rootless:rootless /data
|
||||||
|
|
||||||
|
USER rootless
|
||||||
|
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|
||||||
@@ -42,14 +42,12 @@ func Execute(ctx context.Context) {
|
|||||||
rootCmd.AddCommand(registerCmd)
|
rootCmd.AddCommand(registerCmd)
|
||||||
|
|
||||||
// ./act_runner daemon
|
// ./act_runner daemon
|
||||||
var daemArgs daemonArgs
|
|
||||||
daemonCmd := &cobra.Command{
|
daemonCmd := &cobra.Command{
|
||||||
Use: "daemon",
|
Use: "daemon",
|
||||||
Short: "Run as a runner daemon",
|
Short: "Run as a runner daemon",
|
||||||
Args: cobra.MaximumNArgs(0),
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: runDaemon(ctx, &daemArgs, &configFile),
|
RunE: runDaemon(ctx, &configFile),
|
||||||
}
|
}
|
||||||
daemonCmd.Flags().BoolVar(&daemArgs.Once, "once", false, "Run one job then exit")
|
|
||||||
rootCmd.AddCommand(daemonCmd)
|
rootCmd.AddCommand(daemonCmd)
|
||||||
|
|
||||||
// ./act_runner exec
|
// ./act_runner exec
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
"gitea.com/gitea/act_runner/internal/pkg/ver"
|
"gitea.com/gitea/act_runner/internal/pkg/ver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) func(cmd *cobra.Command, args []string) error {
|
func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command, args []string) error {
|
||||||
return func(cmd *cobra.Command, args []string) error {
|
return func(cmd *cobra.Command, args []string) error {
|
||||||
cfg, err := config.LoadDefault(*configFile)
|
cfg, err := config.LoadDefault(*configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -122,24 +122,9 @@ func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) fu
|
|||||||
|
|
||||||
poller := poll.New(cfg, cli, runner)
|
poller := poll.New(cfg, cli, runner)
|
||||||
|
|
||||||
if daemArgs.Once {
|
go poller.Poll()
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
defer close(done)
|
|
||||||
poller.PollOnce()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// shutdown when we complete a job or cancel is requested
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
case <-done:
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
go poller.Poll()
|
|
||||||
|
|
||||||
<-ctx.Done()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
<-ctx.Done()
|
||||||
log.Infof("runner: %s shutdown initiated, waiting %s for running jobs to complete before shutting down", resp.Msg.Runner.Name, cfg.Runner.ShutdownTimeout)
|
log.Infof("runner: %s shutdown initiated, waiting %s for running jobs to complete before shutting down", resp.Msg.Runner.Name, cfg.Runner.ShutdownTimeout)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), cfg.Runner.ShutdownTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), cfg.Runner.ShutdownTimeout)
|
||||||
@@ -149,15 +134,10 @@ func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) fu
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("runner: %s cancelled in progress jobs during shutdown", resp.Msg.Runner.Name)
|
log.Warnf("runner: %s cancelled in progress jobs during shutdown", resp.Msg.Runner.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type daemonArgs struct {
|
|
||||||
Once bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// initLogging setup the global logrus logger.
|
// initLogging setup the global logrus logger.
|
||||||
func initLogging(cfg *config.Config) {
|
func initLogging(cfg *config.Config) {
|
||||||
isTerm := isatty.IsTerminal(os.Stdout.Fd())
|
isTerm := isatty.IsTerminal(os.Stdout.Fd())
|
||||||
|
|||||||
@@ -70,15 +70,6 @@ func (p *Poller) Poll() {
|
|||||||
close(p.done)
|
close(p.done)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Poller) PollOnce() {
|
|
||||||
limiter := rate.NewLimiter(rate.Every(p.cfg.Runner.FetchInterval), 1)
|
|
||||||
|
|
||||||
p.pollOnce(limiter)
|
|
||||||
|
|
||||||
// signal that we're done
|
|
||||||
close(p.done)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Poller) Shutdown(ctx context.Context) error {
|
func (p *Poller) Shutdown(ctx context.Context) error {
|
||||||
p.shutdownPolling()
|
p.shutdownPolling()
|
||||||
|
|
||||||
@@ -110,19 +101,6 @@ func (p *Poller) Shutdown(ctx context.Context) error {
|
|||||||
|
|
||||||
func (p *Poller) poll(wg *sync.WaitGroup, limiter *rate.Limiter) {
|
func (p *Poller) poll(wg *sync.WaitGroup, limiter *rate.Limiter) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for {
|
|
||||||
p.pollOnce(limiter)
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-p.pollingCtx.Done():
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Poller) pollOnce(limiter *rate.Limiter) {
|
|
||||||
for {
|
for {
|
||||||
if err := limiter.Wait(p.pollingCtx); err != nil {
|
if err := limiter.Wait(p.pollingCtx); err != nil {
|
||||||
if p.pollingCtx.Err() != nil {
|
if p.pollingCtx.Err() != nil {
|
||||||
@@ -136,7 +114,6 @@ func (p *Poller) pollOnce(limiter *rate.Limiter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.runTaskWithRecover(p.jobsCtx, task)
|
p.runTaskWithRecover(p.jobsCtx, task)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,7 +186,6 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
|||||||
Workdir: filepath.FromSlash(fmt.Sprintf("/%s/%s", strings.TrimLeft(r.cfg.Container.WorkdirParent, "/"), preset.Repository)),
|
Workdir: filepath.FromSlash(fmt.Sprintf("/%s/%s", strings.TrimLeft(r.cfg.Container.WorkdirParent, "/"), preset.Repository)),
|
||||||
BindWorkdir: false,
|
BindWorkdir: false,
|
||||||
ActionCacheDir: filepath.FromSlash(r.cfg.Host.WorkdirParent),
|
ActionCacheDir: filepath.FromSlash(r.cfg.Host.WorkdirParent),
|
||||||
ActionOfflineMode: r.cfg.Cache.OfflineMode,
|
|
||||||
|
|
||||||
ReuseContainers: false,
|
ReuseContainers: false,
|
||||||
ForcePull: r.cfg.Container.ForcePull,
|
ForcePull: r.cfg.Container.ForcePull,
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ cache:
|
|||||||
# If it's specified, act_runner will use this URL as the ACTIONS_CACHE_URL rather than start a server by itself.
|
# If it's specified, act_runner will use this URL as the ACTIONS_CACHE_URL rather than start a server by itself.
|
||||||
# The URL should generally end with "/".
|
# The URL should generally end with "/".
|
||||||
external_server: ""
|
external_server: ""
|
||||||
offline_mode: false
|
|
||||||
|
|
||||||
container:
|
container:
|
||||||
# Specifies the network to which the container will connect.
|
# Specifies the network to which the container will connect.
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ type Cache struct {
|
|||||||
Host string `yaml:"host"` // Host specifies the caching host.
|
Host string `yaml:"host"` // Host specifies the caching host.
|
||||||
Port uint16 `yaml:"port"` // Port specifies the caching port.
|
Port uint16 `yaml:"port"` // Port specifies the caching port.
|
||||||
ExternalServer string `yaml:"external_server"` // ExternalServer specifies the URL of external cache server
|
ExternalServer string `yaml:"external_server"` // ExternalServer specifies the URL of external cache server
|
||||||
OfflineMode bool `yaml:"offline_mode"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Container represents the configuration for the container.
|
// Container represents the configuration for the container.
|
||||||
|
|||||||
9
scripts/rootless.sh
Executable file
9
scripts/rootless.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# wait for docker daemon
|
||||||
|
while ! nc -z localhost 2376 </dev/null; do
|
||||||
|
echo 'waiting for docker daemon...'
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
|
||||||
|
. /opt/act/run.sh
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
exec s6-svscanctl -t /etc/s6
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
s6-svwait -U /etc/s6/docker
|
|
||||||
|
|
||||||
exec run.sh
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
if ! docker info &> /dev/null; then
|
|
||||||
echo "Waiting for Docker daemon to start..."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
exec s6-svscanctl -t /etc/s6
|
|
||||||
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
3
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
exec s6-notifyoncheck dockerd-entrypoint.sh
|
|
||||||
17
scripts/supervisord.conf
Normal file
17
scripts/supervisord.conf
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
[supervisord]
|
||||||
|
nodaemon=true
|
||||||
|
logfile=/dev/null
|
||||||
|
logfile_maxbytes=0
|
||||||
|
|
||||||
|
[program:dockerd]
|
||||||
|
command=/usr/local/bin/dockerd-entrypoint.sh
|
||||||
|
|
||||||
|
[program:act_runner]
|
||||||
|
stdout_logfile=/dev/fd/1
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
redirect_stderr=true
|
||||||
|
command=/opt/act/rootless.sh
|
||||||
|
|
||||||
|
[eventlistener:processes]
|
||||||
|
command=bash -c "echo READY && read line && kill -SIGQUIT $PPID"
|
||||||
|
events=PROCESS_STATE_STOPPED,PROCESS_STATE_EXITED,PROCESS_STATE_FATAL
|
||||||
Reference in New Issue
Block a user