chore: CI, multi-arch docker buildx (Fix #44)
This commit is contained in:
parent
b60994a524
commit
8736198b8e
9 changed files with 105 additions and 90 deletions
34
.github/workflows/build.yml
vendored
Normal file
34
.github/workflows/build.yml
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
name: build
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
- name: Test
|
||||
run: go test -v ./...
|
||||
|
||||
- name: build docker image on multiple platform
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v5,linux/arm/v6,linux/arm/v7,darwin/amd64,darwin/arm64,windows/amd64
|
||||
push: false
|
37
.github/workflows/docker-push.yml
vendored
Normal file
37
.github/workflows/docker-push.yml
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
name: CI to Docker Hub
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Check Out Repo
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v5,linux/arm/v6,linux/arm/v7,darwin/amd64,darwin/arm64,windows/amd64
|
||||
push: true
|
||||
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/gostatic:latest
|
||||
|
||||
- name: Image digest
|
||||
run: echo ${{ steps.docker_build.outputs.digest }}
|
16
Dockerfile
16
Dockerfile
|
@ -1,10 +1,22 @@
|
|||
# stage 0
|
||||
FROM golang:latest as builder
|
||||
FROM --platform=$BUILDPLATFORM golang:latest as builder
|
||||
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
WORKDIR /go/src/github.com/PierreZ/goStatic
|
||||
COPY . .
|
||||
|
||||
RUN mkdir ./bin && \
|
||||
apt-get update && apt-get install -y upx && \
|
||||
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags="-s" -tags netgo -installsuffix netgo -o ./bin/goStatic && \
|
||||
|
||||
# getting right vars from docker buildx
|
||||
# especially to handle linux/arm/v6 for example
|
||||
GOOS=$(echo $TARGETPLATFORM | cut -f1 -d/) && \
|
||||
GOARCH=$(echo $TARGETPLATFORM | cut -f2 -d/) && \
|
||||
GOARM=$(echo $TARGETPLATFORM | cut -f3 -d/ | sed "s/v//" ) && \
|
||||
|
||||
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build ${BUILD_ARGS} -ldflags="-s" -tags netgo -installsuffix netgo -o ./bin/goStatic && \
|
||||
|
||||
mkdir ./bin/etc && \
|
||||
ID=$(shuf -i 100-9999 -n 1) && \
|
||||
upx -9 ./bin/goStatic && \
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
# stage 0
|
||||
FROM golang:latest as builder
|
||||
WORKDIR /go/src/github.com/PierreZ/goStatic
|
||||
COPY . .
|
||||
RUN mkdir ./bin && \
|
||||
apt-get update && apt-get install -y upx && \
|
||||
CGO_ENABLED=0 GOARCH=arm GOARM=5 GOOS=linux go build -ldflags="-s" -tags netgo -installsuffix netgo -o ./bin/goStatic && \
|
||||
mkdir ./bin/etc && \
|
||||
ID=$(shuf -i 100-9999 -n 1) && \
|
||||
upx -9 ./bin/goStatic && \
|
||||
echo $ID && \
|
||||
echo "appuser:x:$ID:$ID::/sbin/nologin:/bin/false" > ./bin/etc/passwd && \
|
||||
echo "appgroup:x:$ID:appuser" > ./bin/etc/group
|
||||
|
||||
# stage 1
|
||||
FROM scratch
|
||||
WORKDIR /
|
||||
COPY --from=builder /go/src/github.com/PierreZ/goStatic/bin/ .
|
||||
USER appuser
|
||||
ENTRYPOINT ["/goStatic"]
|
|
@ -1,20 +0,0 @@
|
|||
# stage 0
|
||||
FROM golang:latest as builder
|
||||
WORKDIR /go/src/github.com/PierreZ/goStatic
|
||||
COPY . .
|
||||
RUN mkdir ./bin && \
|
||||
apt-get update && apt-get install -y upx && \
|
||||
CGO_ENABLED=0 GOARCH=arm GOARM=6 GOOS=linux go build -ldflags="-s" -tags netgo -installsuffix netgo -o ./bin/goStatic && \
|
||||
mkdir ./bin/etc && \
|
||||
ID=$(shuf -i 100-9999 -n 1) && \
|
||||
upx -9 ./bin/goStatic && \
|
||||
echo $ID && \
|
||||
echo "appuser:x:$ID:$ID::/sbin/nologin:/bin/false" > ./bin/etc/passwd && \
|
||||
echo "appgroup:x:$ID:appuser" > ./bin/etc/group
|
||||
|
||||
# stage 1
|
||||
FROM scratch
|
||||
WORKDIR /
|
||||
COPY --from=builder /go/src/github.com/PierreZ/goStatic/bin/ .
|
||||
USER appuser
|
||||
ENTRYPOINT ["/goStatic"]
|
|
@ -1,20 +0,0 @@
|
|||
# stage 0
|
||||
FROM golang:latest as builder
|
||||
WORKDIR /go/src/github.com/PierreZ/goStatic
|
||||
COPY . .
|
||||
RUN mkdir ./bin && \
|
||||
apt-get update && apt-get install -y upx && \
|
||||
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -ldflags="-s" -tags netgo -installsuffix netgo -o ./bin/goStatic && \
|
||||
mkdir ./bin/etc && \
|
||||
ID=$(shuf -i 100-9999 -n 1) && \
|
||||
upx -9 ./bin/goStatic && \
|
||||
echo $ID && \
|
||||
echo "appuser:x:$ID:$ID::/sbin/nologin:/bin/false" > ./bin/etc/passwd && \
|
||||
echo "appgroup:x:$ID:appuser" > ./bin/etc/group
|
||||
|
||||
# stage 1
|
||||
FROM scratch
|
||||
WORKDIR /
|
||||
COPY --from=builder /go/src/github.com/PierreZ/goStatic/bin/ .
|
||||
USER appuser
|
||||
ENTRYPOINT ["/goStatic"]
|
|
@ -1,20 +0,0 @@
|
|||
# stage 0
|
||||
FROM golang:latest as builder
|
||||
WORKDIR /go/src/github.com/PierreZ/goStatic
|
||||
COPY . .
|
||||
RUN mkdir ./bin && \
|
||||
apt-get update && apt-get install -y upx && \
|
||||
CGO_ENABLED=0 GOARCH=arm GOARM=7 GOOS=linux go build -ldflags="-s" -tags netgo -installsuffix netgo -o ./bin/goStatic && \
|
||||
mkdir ./bin/etc && \
|
||||
ID=$(shuf -i 100-9999 -n 1) && \
|
||||
upx -9 ./bin/goStatic && \
|
||||
echo $ID && \
|
||||
echo "appuser:x:$ID:$ID::/sbin/nologin:/bin/false" > ./bin/etc/passwd && \
|
||||
echo "appgroup:x:$ID:appuser" > ./bin/etc/group
|
||||
|
||||
# stage 1
|
||||
FROM scratch
|
||||
WORKDIR /
|
||||
COPY --from=builder /go/src/github.com/PierreZ/goStatic/bin/ .
|
||||
USER appuser
|
||||
ENTRYPOINT ["/goStatic"]
|
25
README.md
25
README.md
|
@ -1,15 +1,15 @@
|
|||
# goStatic [](https://hub.docker.com/r/pierrezemb/gostatic/) [](https://hub.docker.com/r/pierrezemb/gostatic/) [](https://travis-ci.org/PierreZ/goStatic) [](https://godoc.org/github.com/PierreZ/goStatic)
|
||||
A really small static web server for Docker
|
||||
A really small, multi-arch, static web server for Docker
|
||||
|
||||
### The goal
|
||||
## The goal
|
||||
My goal is to create to smallest docker container for my web static files. The advantage of Go is that you can generate a fully static binary, so that you don't need anything else.
|
||||
|
||||
### Wait, I've been using old versions of GoStatic and things have changed!
|
||||
|
||||
Yeah, decided to drop support of unsecured HTTPS. Two-years ago, when I started GoStatic, there was no automatic HTTPS available. Nowadays, thanks to Let's Encrypt, it's really easy to do so. If you need HTTPS, I recommend [caddy](https://caddyserver.com).
|
||||
|
||||
### Features
|
||||
* A fully static web server in 6MB
|
||||
## Features
|
||||
* A fully static web server embedded in a `SCRATCH` image
|
||||
* No framework
|
||||
* Web server built for Docker
|
||||
* Light container
|
||||
|
@ -17,7 +17,7 @@ Yeah, decided to drop support of unsecured HTTPS. Two-years ago, when I started
|
|||
* Log enabled
|
||||
* Specify custom response headers per path and filetype [(info)](./docs/header-config.md)
|
||||
|
||||
### Why?
|
||||
## Why?
|
||||
Because the official Golang image is wayyyy too big (around 1/2Gb as you can see below) and could be insecure.
|
||||
|
||||
[](https://imagelayers.io/?images=golang:latest 'Get your own badge on imagelayers.io')
|
||||
|
@ -30,12 +30,12 @@ Many links should provide you with additional info to see my point of view:
|
|||
* [Building Docker Images for Static Go Binaries](https://medium.com/@kelseyhightower/optimizing-docker-images-for-static-binaries-b5696e26eb07)
|
||||
* [Small Docker Images For Go Apps](https://www.ctl.io/developers/blog/post/small-docker-images-for-go-apps)
|
||||
|
||||
### How to use
|
||||
## How to use
|
||||
```
|
||||
docker run -d -p 80:8043 -v path/to/website:/srv/http --name goStatic pierrezemb/gostatic
|
||||
```
|
||||
|
||||
### Usage
|
||||
## Usage
|
||||
|
||||
```
|
||||
./goStatic --help
|
||||
|
@ -68,7 +68,7 @@ Usage of ./goStatic:
|
|||
Define the basic auth. Form must be user:password
|
||||
```
|
||||
|
||||
#### Fallback
|
||||
### Fallback
|
||||
|
||||
The fallback option is principally useful for single-page applications (SPAs) where the browser may request a file, but where part of the path is in fact an internal route in the application, not a file on disk. goStatic supports two possible usages of this option:
|
||||
|
||||
|
@ -76,3 +76,12 @@ The fallback option is principally useful for single-page applications (SPAs) wh
|
|||
2. Using a relative file, which searches up the tree for the specified file
|
||||
|
||||
The second case is useful if you have multiple SPAs within the one filesystem. e.g., */* and */admin*.
|
||||
|
||||
|
||||
## Build
|
||||
|
||||
### Docker images
|
||||
```bash
|
||||
docker buildx create --use --name=cross
|
||||
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v5,linux/arm/v6,linux/arm/v7,darwin/amd64,darwin/arm64,windows/amd64 .
|
||||
```
|
3
go.mod
Normal file
3
go.mod
Normal file
|
@ -0,0 +1,3 @@
|
|||
module github.com/PierreZ/goStatic
|
||||
|
||||
go 1.16
|
Loading…
Reference in a new issue