mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 13:23:07 +01:00
Adds support for multi-arch (#306)
* Uses experimental docker multi-arch * Fixes dockerfile to build node and golang images * Adds ldflags * Adds buildx to push.yml * Adds docker login * Adds login in again * Login using run * Login using run * Adds Makefile * Updates actions * Fixes push
This commit is contained in:
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
node_modules
|
||||||
|
.cache
|
||||||
|
.idea
|
||||||
|
dist
|
||||||
|
.git
|
||||||
|
static
|
||||||
6
.github/golang/Dockerfile
vendored
6
.github/golang/Dockerfile
vendored
@@ -1,6 +0,0 @@
|
|||||||
FROM golang:1.14
|
|
||||||
|
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
|
||||||
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
|
||||||
CMD [""]
|
|
||||||
4
.github/golang/entrypoint.sh
vendored
4
.github/golang/entrypoint.sh
vendored
@@ -1,4 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
go test -cover ./...
|
|
||||||
13
.github/goreleaser/Dockerfile
vendored
13
.github/goreleaser/Dockerfile
vendored
@@ -1,13 +0,0 @@
|
|||||||
FROM golang:1.14-alpine
|
|
||||||
|
|
||||||
RUN apk --no-cache add git nodejs-current nodejs-npm make g++ bash bzr curl docker rpm && \
|
|
||||||
npm i -g npm && \
|
|
||||||
wget https://github.com/goreleaser/goreleaser/releases/latest/download/goreleaser_Linux_x86_64.tar.gz && \
|
|
||||||
tar -xvzf *.tar.gz -C /usr/local/bin && \
|
|
||||||
rm *.gz && \
|
|
||||||
go get -u github.com/gobuffalo/packr/packr
|
|
||||||
|
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
|
||||||
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
|
||||||
CMD [""]
|
|
||||||
18
.github/goreleaser/entrypoint.sh
vendored
18
.github/goreleaser/entrypoint.sh
vendored
@@ -1,18 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
if [ -n "$DOCKER_USERNAME" ] && [ -n "$DOCKER_PASSWORD" ]; then
|
|
||||||
echo "Login to the docker..."
|
|
||||||
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Workaround for github actions when access to different repositories is needed.
|
|
||||||
# Github actions provides a GITHUB_TOKEN secret that can only access the current
|
|
||||||
# repository and you cannot configure it's value.
|
|
||||||
# Access to different repositories is needed by brew for example.
|
|
||||||
|
|
||||||
if [ -n "$GORELEASER_GITHUB_TOKEN" ] ; then
|
|
||||||
export GITHUB_TOKEN=$GORELEASER_GITHUB_TOKEN
|
|
||||||
fi
|
|
||||||
|
|
||||||
npm ci
|
|
||||||
goreleaser $@
|
|
||||||
45
.github/workflows/deploy.yml
vendored
Normal file
45
.github/workflows/deploy.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
name: Test and Release
|
||||||
|
jobs:
|
||||||
|
npm-test:
|
||||||
|
name: npm test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: npm test
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
- name: npm it
|
||||||
|
run: npm it
|
||||||
|
go-test:
|
||||||
|
name: go test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install Go
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: "1.14.x"
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Test
|
||||||
|
run: go test -cover ./...
|
||||||
|
buildx:
|
||||||
|
needs: [go-test, npm-test]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: crazy-max/ghaction-docker-buildx@v1
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
- name: Available platforms
|
||||||
|
run: echo ${{ steps.buildx.outputs.platforms }}
|
||||||
|
- name: Run Buildx
|
||||||
|
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
- name: Run Buildx
|
||||||
|
run: make publish
|
||||||
32
.github/workflows/push.yml
vendored
32
.github/workflows/push.yml
vendored
@@ -1,23 +1,25 @@
|
|||||||
on: push
|
on: push
|
||||||
name: Build, Test and Release
|
name: Test
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
npm-test:
|
||||||
name: npm test
|
name: npm test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
- name: npm test
|
- name: npm test
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
- run: npm it
|
- name: npm it
|
||||||
- name: go test
|
run: npm it
|
||||||
uses: ./.github/golang/
|
go-test:
|
||||||
- name: Release
|
name: go test
|
||||||
uses: ./.github/goreleaser/
|
runs-on: ubuntu-latest
|
||||||
env:
|
steps:
|
||||||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
- name: Install Go
|
||||||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
uses: actions/setup-go@v1
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
REF: ${{ github. ref }}
|
|
||||||
with:
|
with:
|
||||||
args: release
|
go-version: "1.14.x"
|
||||||
if: contains(github.ref, 'tags')
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Test
|
||||||
|
run: go test -cover ./...
|
||||||
|
|||||||
55
Dockerfile
55
Dockerfile
@@ -1,9 +1,56 @@
|
|||||||
FROM alpine:latest as certs
|
# Build assets
|
||||||
RUN apk --update add ca-certificates
|
FROM node:13-alpine as node
|
||||||
|
|
||||||
|
RUN apk add --no-cache git openssh python make g++ util-linux
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# Copy assets to build
|
||||||
|
COPY assets ./assets
|
||||||
|
|
||||||
|
# Do the build
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
|
||||||
|
FROM golang:alpine AS builder
|
||||||
|
|
||||||
|
RUN apk add --no-cache git ca-certificates
|
||||||
|
RUN mkdir /dozzle
|
||||||
|
|
||||||
|
WORKDIR /dozzle
|
||||||
|
|
||||||
|
# Needed for assets
|
||||||
|
RUN go get -u github.com/gobuffalo/packr/packr
|
||||||
|
|
||||||
|
# Copy go mod files
|
||||||
|
COPY go.* ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy assets built with node
|
||||||
|
COPY --from=node /build/static ./static
|
||||||
|
|
||||||
|
# Copy all other files
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Compile static files
|
||||||
|
RUN packr -z
|
||||||
|
|
||||||
|
# Args
|
||||||
|
ARG TAG=dev
|
||||||
|
|
||||||
|
# Build binary
|
||||||
|
RUN CGO_ENABLED=0 go build -ldflags "-s -w -X main.version=$TAG" -o dozzle
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
||||||
ENV PATH=/bin
|
ENV PATH=/bin
|
||||||
ENV DOCKER_API_VERSION 1.38
|
ENV DOCKER_API_VERSION 1.38
|
||||||
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
|
||||||
COPY dozzle /
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
|
COPY --from=builder /dozzle/dozzle /dozzle
|
||||||
|
|
||||||
ENTRYPOINT ["/dozzle"]
|
ENTRYPOINT ["/dozzle"]
|
||||||
|
|||||||
6
Makefile
Normal file
6
Makefile
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
TAG := $(shell git describe --tags)
|
||||||
|
PLATFROMS := linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
|
||||||
|
.PHONY: publish
|
||||||
|
publish:
|
||||||
|
docker buildx build --build-arg TAG=$(TAG) --platform $(PLATFROMS) -t amir20/test:latest -t amir20/test:$(TAG) --push .
|
||||||
5
main.go
5
main.go
@@ -138,7 +138,10 @@ func (h *handler) index(w http.ResponseWriter, req *http.Request) {
|
|||||||
if h.box.Has(req.URL.Path) && req.URL.Path != "" && req.URL.Path != "/" {
|
if h.box.Has(req.URL.Path) && req.URL.Path != "" && req.URL.Path != "/" {
|
||||||
fileServer.ServeHTTP(w, req)
|
fileServer.ServeHTTP(w, req)
|
||||||
} else {
|
} else {
|
||||||
text, _ := h.box.FindString("index.html")
|
text, err := h.box.FindString("index.html")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
text = strings.Replace(text, "__BASE__", "{{ .Base }}", -1)
|
text = strings.Replace(text, "__BASE__", "{{ .Base }}", -1)
|
||||||
tmpl, err := template.New("index.html").Parse(text)
|
tmpl, err := template.New("index.html").Parse(text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user