Skip to content

Commit 28d54c5

Browse files
authored
Miscellaneous updates (#720)
* Update Github action * Bump go 1.24 * Add tests * Better error handling
1 parent 2d7ae0f commit 28d54c5

6 files changed

Lines changed: 425 additions & 99 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,50 @@ jobs:
1313
build:
1414
name: Build Docker Images
1515
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
1619

1720
steps:
1821
- name: Check out repository
19-
uses: actions/checkout@v2
22+
uses: actions/checkout@v4
2023

2124
- name: Set up Docker Buildx
22-
id: buildx
23-
uses: docker/setup-buildx-action@v1
24-
25-
- name: Cache Docker layers
26-
uses: actions/cache@v2.1.4
27-
with:
28-
path: /tmp/.buildx-cache
29-
key: ${{ runner.os }}-buildx-${{ github.sha }}
30-
restore-keys: |
31-
${{ runner.os }}-buildx-
25+
uses: docker/setup-buildx-action@v3
3226

3327
- name: Log in to GitHub Container Registry
3428
if: github.event_name != 'pull_request'
35-
uses: docker/login-action@v1
29+
uses: docker/login-action@v3
3630
with:
3731
registry: ghcr.io
3832
username: ${{ github.actor }}
39-
password: ${{ secrets.GHCR_PAT }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
4034

4135
- name: Login to Docker Hub
4236
if: github.event_name != 'pull_request'
43-
uses: docker/login-action@v1
37+
uses: docker/login-action@v3
4438
with:
4539
username: ${{ secrets.DOCKER_USERNAME }}
4640
password: ${{ secrets.DOCKER_PASSWORD }}
4741

42+
- name: Docker meta
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: |
47+
ghcr.io/lloesche/valheim-server
48+
lloesche/valheim-server
49+
tags: |
50+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
51+
4852
- name: Build and push Docker image
49-
uses: docker/build-push-action@v2
53+
uses: docker/build-push-action@v5
5054
with:
5155
context: .
52-
file: ./Dockerfile
5356
platforms: linux/amd64
5457
push: ${{ github.event_name != 'pull_request' }}
5558
build-args: SOURCE_COMMIT=${{ github.sha }}
56-
tags: |
57-
ghcr.io/lloesche/valheim-server:latest
58-
lloesche/valheim-server:latest
59-
cache-from: type=local,src=/tmp/.buildx-cache
60-
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
61-
62-
- # Temporary fix
63-
# https://github.com/docker/build-push-action/issues/252
64-
# https://github.com/moby/buildkit/issues/1896
65-
name: Move cache
66-
run: |
67-
rm -rf /tmp/.buildx-cache
68-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
59+
tags: ${{ steps.meta.outputs.tags }}
60+
labels: ${{ steps.meta.outputs.labels }}
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ ARG TESTS
44
ARG SOURCE_COMMIT
55
ARG BUSYBOX_VERSION=1.34.1
66
ARG SUPERVISOR_VERSION=4.2.4
7+
ARG GO_VERSION=1.24.0
78

89
RUN apt-get update
910
RUN apt-get -y install apt-utils
10-
RUN apt-get -y install build-essential curl git python3 python3-pip golang shellcheck
11+
RUN apt-get -y install build-essential curl git python3 python3-pip shellcheck
12+
13+
# Install Go 1.24 manually
14+
RUN curl -L -o /tmp/go${GO_VERSION}.linux-amd64.tar.gz https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz \
15+
&& tar -C /usr/local -xzf /tmp/go${GO_VERSION}.linux-amd64.tar.gz \
16+
&& rm /tmp/go${GO_VERSION}.linux-amd64.tar.gz
17+
ENV PATH=$PATH:/usr/local/go/bin
18+
ENV GOPATH=/go
19+
ENV PATH=$PATH:$GOPATH/bin
1120

1221
WORKDIR /build/busybox
1322
RUN curl -L -o /tmp/busybox.tar.bz2 https://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2 \
@@ -20,9 +29,9 @@ RUN curl -L -o /tmp/busybox.tar.bz2 https://busybox.net/downloads/busybox-${BUSY
2029
WORKDIR /build/env2cfg
2130
COPY ./env2cfg/ /build/env2cfg/
2231
RUN if [ "${TESTS:-true}" = true ]; then \
23-
pip3 install tox \
24-
&& tox \
25-
; \
32+
pip3 install tox \
33+
&& tox \
34+
; \
2635
fi
2736
RUN python3 setup.py bdist --format=gztar
2837

@@ -55,17 +64,17 @@ COPY common /usr/local/etc/valheim/
5564
COPY contrib/* /usr/local/share/valheim/contrib/
5665
RUN chmod 755 /usr/local/sbin/bootstrap /usr/local/bin/valheim-*
5766
RUN if [ "${TESTS:-true}" = true ]; then \
58-
shellcheck -a -x -s bash -e SC2034 \
59-
/usr/local/sbin/bootstrap \
60-
/usr/local/bin/valheim-backup \
61-
/usr/local/bin/valheim-is-idle \
62-
/usr/local/bin/valheim-bootstrap \
63-
/usr/local/bin/valheim-server \
64-
/usr/local/bin/valheim-updater \
65-
/usr/local/bin/valheim-plus-updater \
66-
/usr/local/bin/bepinex-updater \
67-
/usr/local/share/valheim/contrib/*.sh \
68-
; \
67+
shellcheck -a -x -s bash -e SC2034 \
68+
/usr/local/sbin/bootstrap \
69+
/usr/local/bin/valheim-backup \
70+
/usr/local/bin/valheim-is-idle \
71+
/usr/local/bin/valheim-bootstrap \
72+
/usr/local/bin/valheim-server \
73+
/usr/local/bin/valheim-updater \
74+
/usr/local/bin/valheim-plus-updater \
75+
/usr/local/bin/bepinex-updater \
76+
/usr/local/share/valheim/contrib/*.sh \
77+
; \
6978
fi
7079
WORKDIR /
7180
RUN rm -rf /usr/local/lib/
@@ -82,10 +91,10 @@ FROM --platform=linux/386 debian:buster-slim as i386-libs
8291
ENV DEBIAN_FRONTEND=noninteractive
8392
RUN apt-get update \
8493
&& apt-get -y --no-install-recommends install \
85-
libc6-dev \
86-
libstdc++6 \
87-
libsdl2-2.0-0 \
88-
libcurl4 \
94+
libc6-dev \
95+
libstdc++6 \
96+
libsdl2-2.0-0 \
97+
libcurl4 \
8998
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
9099

91100

@@ -103,26 +112,26 @@ RUN groupadd -g "${PGID:-0}" -o valheim \
103112
&& apt-get -y --no-install-recommends install apt-utils \
104113
&& apt-get -y dist-upgrade \
105114
&& apt-get -y --no-install-recommends install \
106-
libc6-dev \
107-
libsdl2-2.0-0 \
108-
cron \
109-
curl \
110-
iproute2 \
111-
libcurl4 \
112-
ca-certificates \
113-
procps \
114-
locales \
115-
unzip \
116-
zip \
117-
rsync \
118-
openssh-client \
119-
jq \
120-
python3-minimal \
121-
python3-pkg-resources \
122-
python3-setuptools \
123-
libpulse-dev \
124-
libatomic1 \
125-
libc6 \
115+
libc6-dev \
116+
libsdl2-2.0-0 \
117+
cron \
118+
curl \
119+
iproute2 \
120+
libcurl4 \
121+
ca-certificates \
122+
procps \
123+
locales \
124+
unzip \
125+
zip \
126+
rsync \
127+
openssh-client \
128+
jq \
129+
python3-minimal \
130+
python3-pkg-resources \
131+
python3-setuptools \
132+
libpulse-dev \
133+
libatomic1 \
134+
libc6 \
126135
&& echo 'LANG="en_US.UTF-8"' > /etc/default/locale \
127136
&& echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
128137
&& rm -f /bin/sh \
@@ -164,9 +173,9 @@ RUN groupadd -g "${PGID:-0}" -o valheim \
164173
&& chown valheim:valheim /var/run/valheim \
165174
&& chown -R root:root /opt/steamcmd \
166175
&& chmod 755 /opt/steamcmd/steamcmd.sh \
167-
/opt/steamcmd/linux32/steamcmd \
168-
/opt/steamcmd/linux32/steamerrorreporter \
169-
/usr/bin/supervisord \
176+
/opt/steamcmd/linux32/steamcmd \
177+
/opt/steamcmd/linux32/steamerrorreporter \
178+
/usr/bin/supervisord \
170179
&& cd "/opt/steamcmd" \
171180
&& su - valheim -c "/opt/steamcmd/steamcmd.sh +login anonymous +quit" \
172181
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \

valheim-logfilter/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module github.com/valheim-server-docker/valheim-logfilter
1+
module github.com/lloesche/valheim-server-docker/valheim-logfilter
22

3-
go 1.16
3+
go 1.24
44

5-
require github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
5+
require github.com/golang/glog v1.2.4

valheim-logfilter/go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
2-
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
1+
github.com/golang/glog v1.2.4 h1:CNNw5U8lSiiBk7druxtSHHTsRWcxKoac6kZKm2peBBc=
2+
github.com/golang/glog v1.2.4/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
3+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
4+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=

valheim-logfilter/main.go

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ import (
2929
)
3030

3131
type PatternAction struct {
32-
filter string
33-
cmd string
32+
Filter string
33+
Cmd string
3434
}
3535

3636
type RegexpAction struct {
37-
filter *regexp.Regexp
38-
cmd string
37+
Filter *regexp.Regexp
38+
Cmd string
3939
}
4040

4141
// valheim-logfilter is a string processor for log lines emitted by Valheim dedicated server.
@@ -112,7 +112,7 @@ func main() {
112112
containsFilters = append(containsFilters, PatternAction{varValue, cmd})
113113
} else if strings.HasPrefix(envVar, *envRegexp) {
114114
if foundCmdInEnv {
115-
glog.V(2).Infof("On log lines matching regexp '%s' running '%s", varValue, cmd)
115+
glog.V(2).Infof("On log lines matching regexp '%s' running '%s'", varValue, cmd)
116116
} else {
117117
glog.V(2).Infof("Removing log lines matching regexp '%s'", varValue)
118118
}
@@ -157,51 +157,51 @@ Input:
157157
logLine = string(v)
158158
}
159159
for _, action := range matchFilters {
160-
if logLine == action.filter {
160+
if logLine == action.Filter {
161161
if glog.V(5) {
162-
glog.Infof("Line matched '%s'", action.filter)
162+
glog.Infof("Line matched '%s'", action.Filter)
163163
}
164-
if removeLogLine(action.cmd, logLine) {
164+
if removeLogLine(action.Cmd, logLine) {
165165
continue Input
166166
}
167167
}
168168
}
169169
for _, action := range prefixFilters {
170-
if strings.HasPrefix(logLine, action.filter) {
170+
if strings.HasPrefix(logLine, action.Filter) {
171171
if glog.V(5) {
172-
glog.Infof("Line matched prefix filter '%s'", action.filter)
172+
glog.Infof("Line matched prefix filter '%s'", action.Filter)
173173
}
174-
if removeLogLine(action.cmd, logLine) {
174+
if removeLogLine(action.Cmd, logLine) {
175175
continue Input
176176
}
177177
}
178178
}
179179
for _, action := range suffixFilters {
180-
if strings.HasSuffix(logLine, action.filter) {
180+
if strings.HasSuffix(logLine, action.Filter) {
181181
if glog.V(5) {
182-
glog.Infof("Line matched suffix filter '%s'", action.filter)
182+
glog.Infof("Line matched suffix filter '%s'", action.Filter)
183183
}
184-
if removeLogLine(action.cmd, logLine) {
184+
if removeLogLine(action.Cmd, logLine) {
185185
continue Input
186186
}
187187
}
188188
}
189189
for _, action := range containsFilters {
190-
if strings.Contains(logLine, action.filter) {
190+
if strings.Contains(logLine, action.Filter) {
191191
if glog.V(5) {
192-
glog.Infof("Line contains filter '%s'", action.filter)
192+
glog.Infof("Line contains filter '%s'", action.Filter)
193193
}
194-
if removeLogLine(action.cmd, logLine) {
194+
if removeLogLine(action.Cmd, logLine) {
195195
continue Input
196196
}
197197
}
198198
}
199199
for _, action := range regexpFilters {
200-
if action.filter.MatchString(logLine) {
200+
if action.Filter.MatchString(logLine) {
201201
if glog.V(5) {
202-
glog.Infof("Line matched regexp filter '%s'", action.filter)
202+
glog.Infof("Line matched regexp filter '%s'", action.Filter)
203203
}
204-
if removeLogLine(action.cmd, logLine) {
204+
if removeLogLine(action.Cmd, logLine) {
205205
continue Input
206206
}
207207
}
@@ -243,17 +243,25 @@ func runHook(cmd string, logLine string) {
243243
stdin, err := subProcess.StdinPipe()
244244
if err != nil {
245245
glog.Error(err)
246+
return
246247
}
247248

248249
subProcess.Stdout = os.Stdout
249250
subProcess.Stderr = os.Stderr
250251

251252
if err = subProcess.Start(); err != nil {
252253
glog.Error(err)
254+
return
253255
}
254256
glog.Flush()
255257

256-
io.WriteString(stdin, logLine+"\n")
257-
stdin.Close()
258-
subProcess.Wait()
258+
if _, err = io.WriteString(stdin, logLine+"\n"); err != nil {
259+
glog.Errorf("Failed to write to stdin: %v", err)
260+
}
261+
if err = stdin.Close(); err != nil {
262+
glog.Errorf("Failed to close stdin: %v", err)
263+
}
264+
if err = subProcess.Wait(); err != nil {
265+
glog.Errorf("Command failed: %v", err)
266+
}
259267
}

0 commit comments

Comments
 (0)