1
0
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:
Amir Raminfar
2020-03-18 14:13:35 -07:00
committed by GitHub
parent 4bde14bd6c
commit 3a24c6e665
10 changed files with 129 additions and 61 deletions

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
node_modules
.cache
.idea
dist
.git
static

View File

@@ -1,6 +0,0 @@
FROM golang:1.14
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD [""]

View File

@@ -1,4 +0,0 @@
#!/bin/sh
set -e
go test -cover ./...

View File

@@ -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 [""]

View File

@@ -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
View 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

View File

@@ -1,23 +1,25 @@
on: push
name: Build, Test and Release
name: Test
jobs:
build:
npm-test:
name: npm test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Checkout code
uses: actions/checkout@v2
- name: npm test
uses: actions/setup-node@v1
- run: npm it
- name: go test
uses: ./.github/golang/
- name: Release
uses: ./.github/goreleaser/
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REF: ${{ github. ref }}
- 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:
args: release
if: contains(github.ref, 'tags')
go-version: "1.14.x"
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: go test -cover ./...

View File

@@ -1,9 +1,56 @@
FROM alpine:latest as certs
RUN apk --update add ca-certificates
# Build assets
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
ENV PATH=/bin
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"]

6
Makefile Normal file
View 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 .

View File

@@ -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 != "/" {
fileServer.ServeHTTP(w, req)
} 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)
tmpl, err := template.New("index.html").Parse(text)
if err != nil {