chore: auto build docker image for web
This commit is contained in:
parent
fea5649efb
commit
d863eff7de
7 changed files with 91 additions and 4 deletions
35
.github/workflows/build.yml
vendored
Normal file
35
.github/workflows/build.yml
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
name: build on tag
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ web ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ web ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Build
|
||||||
|
steps:
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Set output
|
||||||
|
id: vars
|
||||||
|
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
|
||||||
|
- name: Build and push
|
||||||
|
id: docker_build
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/go-
|
||||||
|
- name: Image digest
|
||||||
|
run: echo ${{ steps.docker_build.outputs.digest }}
|
||||||
23
Dockerfile
Normal file
23
Dockerfile
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
|
||||||
|
FROM golang:1.17-alpine as builder
|
||||||
|
|
||||||
|
ADD ./ /go-charts
|
||||||
|
|
||||||
|
RUN apk update \
|
||||||
|
&& apk add docker git gcc make \
|
||||||
|
&& cd /go-charts \
|
||||||
|
&& make build
|
||||||
|
|
||||||
|
FROM alpine
|
||||||
|
|
||||||
|
EXPOSE 7001
|
||||||
|
|
||||||
|
COPY --from=builder /go-charts/go-charts /usr/local/bin/go-charts
|
||||||
|
COPY --from=builder /go-charts/entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
|
|
||||||
|
CMD ["go-charts"]
|
||||||
|
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
||||||
|
HEALTHCHECK --timeout=10s --interval=10s CMD [ "wget", "http://127.0.0.1:7001/ping", "-q", "-O", "-"]
|
||||||
9
Makefile
Normal file
9
Makefile
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
export GO111MODULE = on
|
||||||
|
|
||||||
|
.PHONY: default test test-cover dev build
|
||||||
|
|
||||||
|
build:
|
||||||
|
go build -tags netgo -o go-charts
|
||||||
|
|
||||||
|
release:
|
||||||
|
go mod tidy
|
||||||
8
entrypoint.sh
Executable file
8
entrypoint.sh
Executable file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ "${1:0:1}" = '-' ]; then
|
||||||
|
set -- go-charts "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec "$@"
|
||||||
2
go.mod
2
go.mod
|
|
@ -4,7 +4,7 @@ go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/vicanso/elton v1.8.1
|
github.com/vicanso/elton v1.8.1
|
||||||
github.com/vicanso/go-charts v0.0.2-0.20211225121531-18af884865f4
|
github.com/vicanso/go-charts v0.0.2-0.20211226014821-6d53559d49cf
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -22,8 +22,8 @@ github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||||
github.com/vicanso/elton v1.8.1 h1:axrPozxBaTn9qqCJJ+aSGK+/Y8oLuEm0uXM5wm/glIs=
|
github.com/vicanso/elton v1.8.1 h1:axrPozxBaTn9qqCJJ+aSGK+/Y8oLuEm0uXM5wm/glIs=
|
||||||
github.com/vicanso/elton v1.8.1/go.mod h1:BWQknlDpKtw2L5oer3mtBJo/vpBUYUHAjZL3yFV1+ak=
|
github.com/vicanso/elton v1.8.1/go.mod h1:BWQknlDpKtw2L5oer3mtBJo/vpBUYUHAjZL3yFV1+ak=
|
||||||
github.com/vicanso/go-charts v0.0.2-0.20211225121531-18af884865f4 h1:wNuYxF/3fHIyokCxymsCwKWXjMgGC3wm2CH9rI407uA=
|
github.com/vicanso/go-charts v0.0.2-0.20211226014821-6d53559d49cf h1:4+ykVNLlgrXTENY0HkKEQsWUppWeKi9dtSAG0uZKgTU=
|
||||||
github.com/vicanso/go-charts v0.0.2-0.20211225121531-18af884865f4/go.mod h1:Kylthw+IZk7hDvhrj4CTN+DAsLzG01y91FOOElGv7vk=
|
github.com/vicanso/go-charts v0.0.2-0.20211226014821-6d53559d49cf/go.mod h1:Kylthw+IZk7hDvhrj4CTN+DAsLzG01y91FOOElGv7vk=
|
||||||
github.com/vicanso/hes v0.4.1 h1:lq27wDXAljoROtYbFDTL5gY51SdeY+9L0ohEiRadwTU=
|
github.com/vicanso/hes v0.4.1 h1:lq27wDXAljoROtYbFDTL5gY51SdeY+9L0ohEiRadwTU=
|
||||||
github.com/vicanso/hes v0.4.1/go.mod h1:B0l1NIQM/nYw7owAd+hyHuNnAD8Nsx0T6duhVxmXUBY=
|
github.com/vicanso/hes v0.4.1/go.mod h1:B0l1NIQM/nYw7owAd+hyHuNnAD8Nsx0T6duhVxmXUBY=
|
||||||
github.com/vicanso/intranet-ip v0.0.1 h1:cYS+mExFsKqewWSuHtFwAqw/CO66GsheB/P1BPmSTx0=
|
github.com/vicanso/intranet-ip v0.0.1 h1:cYS+mExFsKqewWSuHtFwAqw/CO66GsheB/P1BPmSTx0=
|
||||||
|
|
|
||||||
14
main.go
14
main.go
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"embed"
|
"embed"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/vicanso/elton"
|
"github.com/vicanso/elton"
|
||||||
|
|
@ -16,6 +17,12 @@ var webFS embed.FS
|
||||||
func main() {
|
func main() {
|
||||||
e := elton.New()
|
e := elton.New()
|
||||||
|
|
||||||
|
e.Use(middleware.NewLogger(middleware.LoggerConfig{
|
||||||
|
Format: middleware.LoggerCombined,
|
||||||
|
OnLog: func(s string, _ *elton.Context) {
|
||||||
|
fmt.Println(s)
|
||||||
|
},
|
||||||
|
}))
|
||||||
e.Use(middleware.NewDefaultError())
|
e.Use(middleware.NewDefaultError())
|
||||||
e.Use(middleware.NewDefaultBodyParser())
|
e.Use(middleware.NewDefaultBodyParser())
|
||||||
|
|
||||||
|
|
@ -28,6 +35,11 @@ func main() {
|
||||||
EnableStrongETag: true,
|
EnableStrongETag: true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
e.GET("/ping", func(c *elton.Context) error {
|
||||||
|
c.BodyBuffer = bytes.NewBufferString("pong")
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
e.GET("/", func(c *elton.Context) error {
|
e.GET("/", func(c *elton.Context) error {
|
||||||
buf, err := webFS.ReadFile("web/index.html")
|
buf, err := webFS.ReadFile("web/index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -46,7 +58,7 @@ func main() {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
err := e.ListenAndServe(":3000")
|
err := e.ListenAndServe(":7001")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue