Skip to content

Commit 6af5c3d

Browse files
committed
Apply CI
1 parent ecee29e commit 6af5c3d

File tree

5 files changed

+127
-10
lines changed

5 files changed

+127
-10
lines changed

.github/workflows/release.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: Version
8+
required: true
9+
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Setup Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: "1.16.x"
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@master
26+
27+
- name: Cache
28+
uses: actions/cache@v2
29+
with:
30+
path: ~/go/pkg/mod
31+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
32+
restore-keys: |
33+
${{ runner.os }}-go-
34+
35+
- name: Login to registry
36+
uses: docker/login-action@v1
37+
with:
38+
username: ${{ secrets.DOCKER_USERNAME }}
39+
password: ${{ secrets.DOCKER_TOKEN }}
40+
41+
- name: Tag
42+
run: |
43+
git config user.name "$GITHUB_ACTOR"
44+
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
45+
tag='${{ github.event.inputs.version }}'
46+
git tag --annotate --message "Tag for release $tag" "$tag"
47+
git push origin "refs/tags/$tag"
48+
49+
- name: Release
50+
uses: goreleaser/goreleaser-action@v2
51+
with:
52+
distribution: goreleaser
53+
version: latest
54+
args: release --rm-dist
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
57+
#
58+
# - name: Cache Docker layers
59+
# uses: actions/cache@v2
60+
# with:
61+
# path: /tmp/.buildx-cache
62+
# key: ${{ runner.os }}-nginx-errors-buildx
63+
#
64+
# - name: Build and push
65+
# uses: docker/build-push-action@v2
66+
# with:
67+
# context: .
68+
# push: true
69+
# labels: |
70+
# org.label-schema.schema-version=1.0
71+
# org.label-schema.version=v${{ github.event.inputs.version }}
72+
# org.label-schema.name=nginx-errors
73+
# tags: |
74+
# vietanhs0817/nginx-errors:v${{ github.event.inputs.version }}
75+
# vietanhs0817/nginx-errors:latest
76+
# cache-from: type=local,src=/tmp/.buildx-cache
77+
# cache-to: type=local,dest=/tmp/.buildx-cache-new
78+
#
79+
# - name: Move cache
80+
# run: |
81+
# rm -rf /tmp/.buildx-cache
82+
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache

.goreleaser.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
project_name: nginx-errors
2+
builds:
3+
- main: .
4+
binary: nginx-errors
5+
env:
6+
- CGO_ENABLED=0
7+
goarch:
8+
- amd64
9+
- arm
10+
goos:
11+
- linux
12+
- darwin
13+
archives:
14+
- files:
15+
- README.md
16+
dockers:
17+
- skip_push: false
18+
dockerfile: Dockerfile
19+
use: buildx
20+
image_templates:
21+
- "vietanhs0817/nginx-errors:v{{ .Tag }}"
22+
- "vietanhs0817/nginx-errors:latest"
23+
build_flag_templates:
24+
- --label=org.label-schema.schema-version=1.0
25+
- --label=org.label-schema.version={{ .Version }}
26+
- --label=org.label-schema.name={{ .ProjectName }}
27+
- --label=org.label-schema.build-date={{ .Date }}
28+
checksum:
29+
name_template: 'checksums.txt'
30+
snapshot:
31+
name_template: "{{ .Tag }}-next"

Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ WORKDIR /src
44

55
COPY . .
66

7-
RUN CGO_ENABLED=0 GOOS=linux go build -o nginx-errors .
7+
RUN go mod download
8+
9+
RUN GO111MODULE=off CGO_ENABLED=0 GOOS=linux go build -o nginx-errors .
810

911
FROM debian:stretch
1012

13+
WORKDIR /
14+
1115
RUN apt-get update && \
1216
apt install -y ca-certificates && \
1317
rm -rf /var/lib/apt/lists/*
1418

19+
COPY --from=builder /src/nginx-errors .
1520

16-
COPY --from=builder /src/nginx-errors /
17-
18-
COPY www /www
21+
COPY ./www /www
1922

2023
ENTRYPOINT ["/nginx-errors"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Nginx Errors
22

3-
This is an additional ingress nginx's default backend with custom error page.
3+
This is an additional ingres-nginx's default backend with custom error page.

main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ package main
33
import (
44
"fmt"
55
"html/template"
6+
"log"
67
"net/http"
8+
"path"
79
)
810

911
func main() {
10-
//errFilesPath := GetEnvAsStringOrFallback("ERROR_FILES_PATH", "/www")
12+
port := GetEnvAsStringOrFallback("PORT", "8080")
13+
errFilesPath := GetEnvAsStringOrFallback("ERROR_FILES_PATH", "/www")
1114

12-
t := template.Must(template.ParseGlob("./www/*.html"))
15+
t := template.Must(template.ParseGlob(path.Join(errFilesPath, "*.html")))
1316

1417
http.HandleFunc("/", errorHandler(t))
1518

1619
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
1720
w.WriteHeader(http.StatusOK)
1821
})
1922

20-
if err := http.ListenAndServe(fmt.Sprintf(":8080"), nil); err != nil {
21-
panic(err)
22-
}
23+
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
2324
}

0 commit comments

Comments
 (0)