Skip to content

Commit dcee519

Browse files
authored
fix: CI Docker build (#92)
* fix: CI Docker build invalid ref to Dockerfile * feat: optimizing go & npm build by levaraging cache * chore: bump go version
1 parent 20d9534 commit dcee519

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

.github/workflows/build-image.yaml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@ jobs:
3535
- name: Set up QEMU
3636
uses: docker/setup-qemu-action@v3
3737

38-
- name: Generate Docker metadata
39-
id: meta
40-
uses: docker/metadata-action@v5
41-
with:
42-
images: |
43-
xblaz3kx/${{ github.repository }}
44-
tags: |
45-
type=ref,event=branch
46-
type=semver,pattern={{version}}
47-
type=semver,pattern={{major}}.{{minor}}
48-
flavor: |
49-
latest=true
50-
5138
- name: Set up Docker Buildx
5239
id: buildx
5340
uses: docker/setup-buildx-action@v3
@@ -71,13 +58,28 @@ jobs:
7158
username: ${{ secrets.DOCKER_HUB_USERNAME }}
7259
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
7360

61+
- name: Generate Docker metadata
62+
id: meta
63+
uses: docker/metadata-action@v5
64+
with:
65+
images: |
66+
xblaz3kx/chargepi
67+
tags: |
68+
type=ref,event=branch
69+
type=semver,pattern={{version}}
70+
type=semver,pattern={{major}}.{{minor}}
71+
type=sha,event=pr
72+
flavor: |
73+
latest=true
74+
7475
- name: Build and push
7576
uses: docker/build-push-action@v6
7677
with:
7778
context: .
7879
target: chargepi
79-
build-args: --build-arg READER_CONNECTION_TYPE="pn532_uart"
80-
file: ./build/package/Dockerfile
80+
build-args: |
81+
READER_CONNECTION_TYPE="pn532_uart"
82+
file: ./build/Dockerfile
8183
platforms: linux/arm64
82-
push: true
84+
push: ${{ github.event_name == 'push' }}
8385
tags: ${{ steps.meta.outputs.tags }}

build/Dockerfile

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
FROM --platform=$BUILDPLATFORM golang:1.18 as base
1+
FROM --platform=$BUILDPLATFORM golang:1.23.0 AS base
22

3-
COPY . /ChargePi/src
43
WORKDIR /ChargePi/src
4+
COPY . /ChargePi/src
55

66
ARG READER_TYPE
77
ENV READER_TYPE=$READER_TYPE
88

9+
ENV GOCACHE=/root/.cache/go-build
10+
ENV GOMODCACHE=/root/.cache/go-build
11+
ENV GO111MODULE=on
12+
913
# Install dependencies
1014
RUN chmod +x /ChargePi/src/scripts/install-dependencies.sh
1115
RUN /ChargePi/src/scripts/install-dependencies.sh $READER_TYPE 0
@@ -15,20 +19,22 @@ ENV GOARCH=arm64
1519
ENV CGO=1
1620

1721
# Compile the client
18-
RUN go mod download
22+
RUN --mount=type=cache,target=/root/.cache/go-build go mod download
1923
RUN go mod verify
20-
RUN go build -o ChargePi .
24+
RUN --mount=type=cache,target="/root/.cache/go-build" go build -o ChargePi .
2125

2226
FROM node:19 as build-ui
2327

24-
COPY ./ui /ui
2528
WORKDIR /ui
2629

27-
RUN npm install
30+
COPY ./ui/package*.json .
31+
COPY ./ui .
32+
33+
RUN --mount=type=cache,target=/root/.npm npm install
2834
RUN npm run build
2935

3036
# Test the client
31-
FROM --platform=$BUILDPLATFORM vektra/mockery:v2.9.4 as test
37+
FROM --platform=$BUILDPLATFORM vektra/mockery:v2.9.4 AS test
3238

3339
COPY --from=base /ChargePi/src /ChargePi/src
3440
WORKDIR /ChargePi/src
@@ -44,7 +50,7 @@ RUN mockery
4450
# Run tests
4551
CMD ["go", "test","-v","./..."]
4652

47-
FROM --platform=$BUILDPLATFORM alpine as chargepi
53+
FROM --platform=$BUILDPLATFORM alpine AS chargepi
4854

4955
WORKDIR /etc/ChargePi
5056

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module github.com/ChargePi/ChargePi-go
22

3-
go 1.22.1
3+
go 1.23.0
4+
45
toolchain go1.23.7
56

67
require (
@@ -46,6 +47,7 @@ require (
4647
github.com/orandin/lumberjackrus v1.0.1
4748
github.com/pkg/errors v0.9.1
4849
github.com/toorop/gin-logrus v0.0.0-20210225092905-2c785434f26f
50+
github.com/warthog618/modem v0.4.0
4951
)
5052

5153
require (
@@ -103,6 +105,7 @@ require (
103105
github.com/spf13/afero v1.11.0 // indirect
104106
github.com/spf13/cast v1.6.0 // indirect
105107
github.com/spf13/pflag v1.0.5 // indirect
108+
github.com/stretchr/objx v0.5.2 // indirect
106109
github.com/subosito/gotenv v1.6.0 // indirect
107110
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
108111
github.com/ugorji/go/codec v1.2.12 // indirect

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8
233233
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
234234
github.com/nicksnyder/go-i18n/v2 v2.2.1 h1:aOzRCdwsJuoExfZhoiXHy4bjruwCMdt5otbYojM/PaA=
235235
github.com/nicksnyder/go-i18n/v2 v2.2.1/go.mod h1:fF2++lPHlo+/kPaj3nB0uxtPwzlPm+BlgwGX7MkeGj0=
236+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
236237
github.com/oapi-codegen/runtime v1.0.0 h1:P4rqFX5fMFWqRzY9M/3YF9+aPSPPB06IzP2P7oOxrWo=
237238
github.com/oapi-codegen/runtime v1.0.0/go.mod h1:LmCUMQuPB4M/nLXilQXhHw+BLZdDb18B34OO356yJ/A=
238239
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88=
@@ -316,6 +317,7 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
316317
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
317318
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
318319
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
320+
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
319321
github.com/tavsec/gin-healthcheck v1.6.3 h1:iwUljulXw71BK+16k/MNGGWG5pFISv1UNw3xQNKxMX4=
320322
github.com/tavsec/gin-healthcheck v1.6.3/go.mod h1:fc1owE+lhHxEwAq2MQog7hgBTZGbCOqbEHvwhXIytkQ=
321323
github.com/toorop/gin-logrus v0.0.0-20210225092905-2c785434f26f h1:oqdnd6OGlOUu1InG37hWcCB3a+Jy3fwjylyVboaNMwY=
@@ -329,6 +331,9 @@ github.com/warthog618/go-gpiosim v0.1.0 h1:2rTMTcKUVZxpUuvRKsagnKAbKpd3Bwffp87xy
329331
github.com/warthog618/go-gpiosim v0.1.0/go.mod h1:Ngx/LYI5toxHr4E+Vm6vTgCnt0of0tktsSuMUEJ2wCI=
330332
github.com/warthog618/gpiod v0.8.2 h1:2HgQ9pNowPp7W77sXhX5ut5Tqq1WoS3t7bXYDxtYvxc=
331333
github.com/warthog618/gpiod v0.8.2/go.mod h1:O7BNpHjCn/4YS5yFVmoFZAlY1LuYuQ8vhPf0iy/qdi4=
334+
github.com/warthog618/modem v0.4.0 h1:QmNRbVopcJYTEalWePSgKd5rhpQW5x/yptojTFVdjjg=
335+
github.com/warthog618/modem v0.4.0/go.mod h1:9b3nNrk7JZRskP+TpHQppfz5QxRKkQGdgeq2Fi0QHcI=
336+
github.com/warthog618/sms v0.3.0/go.mod h1:+bYZGeBxu003sxD5xhzsrIPBAjPBzTABsRTwSpd7ld4=
332337
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
333338
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
334339
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
@@ -405,6 +410,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
405410
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
406411
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
407412
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
413+
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
408414
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
409415
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
410416
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -474,6 +480,7 @@ google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojt
474480
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
475481
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
476482
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
483+
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
477484
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
478485
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
479486
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=

0 commit comments

Comments
 (0)