initial commit

This commit is contained in:
Pavel 2022-07-26 16:24:27 +03:00
commit 4213cf2e72
16 changed files with 397 additions and 0 deletions

15
.editorconfig Normal file
View File

@ -0,0 +1,15 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_size = 2
indent_style = space
[*.md]
trim_trailing_whitespace = false

6
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

110
.github/workflows/buildx.yml vendored Normal file
View File

@ -0,0 +1,110 @@
name: buildx
on:
schedule:
- cron: "37 06 * * *"
pull_request:
push:
jobs:
buildx:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
docker-file:
- path: 1.16
tags: "1.16"
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/arm/v7,linux/arm/v6
- path: 1.16-3.13
tags: "1.16-3.13"
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/arm/v7,linux/arm/v6
- path: 1.17
tags: "1.17"
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/arm/v7,linux/arm/v6
- path: 1.17-3.13
tags: "1.17-3.13"
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/arm/v7,linux/arm/v6
- path: 1.18
tags: "1.18"
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/arm/v7,linux/arm/v6
- path: 1.18-3.13
tags: "1.18-3.13"
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/arm/v7,linux/arm/v6
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare
id: prepare
run: |
DOCKER_IMAGE=neur0toxine/golang-alpine-dumb-init
TEMP="${{ matrix.docker-file.tags }}"
TAGZ=($TEMP)
VERSION=${TAGZ[0]}
for i in "${!TAGZ[@]}"; do
if [ "$i" -eq "0" ];
then
TAGS="${DOCKER_IMAGE}:${TAGZ[$i]}"
else
TAGS="${TAGS},${DOCKER_IMAGE}:${TAGZ[$i]}"
fi
done
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2.0.0
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2.0.0
with:
install: true
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Docker Buildx (build)
uses: docker/build-push-action@v3.0.0
if: success() && !contains(github.ref, 'master')
with:
push: false
context: ./${{ matrix.docker-file.path }}
file: ./${{ matrix.docker-file.path }}/Dockerfile
build-args: REFRESHED_AT=$(date +%Y-%m-%d)
platforms: ${{ matrix.docker-file.platforms }}
tags: ${{ steps.prepare.outputs.tags }}
- name: Docker Login
if: success() && contains(github.ref, 'master')
uses: docker/login-action@v2.0.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker Buildx (push)
uses: docker/build-push-action@v3.0.0
if: success() && contains(github.ref, 'master')
with:
push: true
context: ./${{ matrix.docker-file.path }}
file: ./${{ matrix.docker-file.path }}/Dockerfile
build-args: REFRESHED_AT=$(date +%Y-%m-%d)
platforms: ${{ matrix.docker-file.platforms }}
tags: ${{ steps.prepare.outputs.tags }}
- name: Inspect Image
if: always() && github.event_name != 'pull_request' && contains(github.ref, 'master')
run: |
docker buildx imagetools inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}
- name: Clear
if: always() && github.event_name != 'pull_request'
run: |
rm -f ${HOME}/.docker/config.json

17
.github/workflows/dockerimage.yml vendored Normal file
View File

@ -0,0 +1,17 @@
name: Test Docker image
on: [push, pull_request, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: |
docker run -i $(docker build -q 1.16) /bin/sh -c "go version && bash --version && make --version && git --version && ssh -V && gcc --version && jq --version && curl --version && air -v && dumb-init --version"
docker run -i $(docker build -q 1.16-3.13) /bin/sh -c "go version && bash --version && make --version && git --version && ssh -V && gcc --version && jq --version && curl --version && air -v && dumb-init --version"
docker run -i $(docker build -q 1.17) /bin/sh -c "go version && bash --version && make --version && git --version && ssh -V && gcc --version && jq --version && curl --version && air -v && dumb-init --version"
docker run -i $(docker build -q 1.17-3.13) /bin/sh -c "go version && bash --version && make --version && git --version && ssh -V && gcc --version && jq --version && curl --version && air -v && dumb-init --version"
docker run -i $(docker build -q 1.18) /bin/sh -c "go version && bash --version && make --version && git --version && ssh -V && gcc --version && jq --version && curl --version && air -v && dumb-init --version"
docker run -i $(docker build -q 1.18-3.13) /bin/sh -c "go version && bash --version && make --version && git --version && ssh -V && gcc --version && jq --version && curl --version && air -v && dumb-init --version"

11
.github/workflows/hadolint.yml vendored Normal file
View File

@ -0,0 +1,11 @@
name: Lint Dockerfiles
on: [push, pull_request]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- run: brew install hadolint
- run: hadolint {1.16,1.16-3.13,1.17,1.17-3.13,1.18,1.18-3.13}/Dockerfile

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.DS_Store

3
.hadolint.yaml Normal file
View File

@ -0,0 +1,3 @@
ignored:
- DL3018
- DL3017

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": "./.github/workflows/hadolint.yml"
}
}

11
1.16-3.13/Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM golang:1.16-alpine3.13
RUN apk add --no-cache bash make git gcc libc-dev jq curl dumb-init
RUN cd /tmp && \
git clone https://github.com/go-delve/delve && \
cd delve && \
go install github.com/go-delve/delve/cmd/dlv && \
cd .. && \
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin && \
rm -rf delve && \
chmod -R 777 /go
ENTRYPOINT ["/usr/bin/dumb-init", "--"]

11
1.16/Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM golang:1.16-alpine
RUN apk add --no-cache bash make git gcc libc-dev jq curl dumb-init
RUN cd /tmp && \
git clone https://github.com/go-delve/delve && \
cd delve && \
go install github.com/go-delve/delve/cmd/dlv && \
cd .. && \
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin && \
rm -rf delve && \
chmod -R 777 /go
ENTRYPOINT ["/usr/bin/dumb-init", "--"]

11
1.17-3.13/Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM golang:1.17-alpine3.13
RUN apk add --no-cache bash make git gcc libc-dev jq curl dumb-init
RUN cd /tmp && \
git clone https://github.com/go-delve/delve && \
cd delve && \
go install github.com/go-delve/delve/cmd/dlv && \
cd .. && \
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin && \
rm -rf delve && \
chmod -R 777 /go
ENTRYPOINT ["/usr/bin/dumb-init", "--"]

11
1.17/Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM golang:1.17-alpine
RUN apk add --no-cache bash make git gcc libc-dev jq curl dumb-init
RUN cd /tmp && \
git clone https://github.com/go-delve/delve && \
cd delve && \
go install github.com/go-delve/delve/cmd/dlv && \
cd .. && \
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin && \
rm -rf delve && \
chmod -R 777 /go
ENTRYPOINT ["/usr/bin/dumb-init", "--"]

117
1.18-3.13/Dockerfile Normal file
View File

@ -0,0 +1,117 @@
FROM alpine:3.13
RUN apk add --no-cache ca-certificates
# set up nsswitch.conf for Go's "netgo" implementation
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - docker run --rm debian grep '^hosts:' /etc/nsswitch.conf
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
ENV PATH /usr/local/go/bin:$PATH
ENV GOLANG_VERSION 1.18.4
RUN set -eux; \
apk add --no-cache --virtual .fetch-deps gnupg; \
arch="$(apk --print-arch)"; \
url=; \
case "$arch" in \
'x86_64') \
export GOAMD64='v1' GOARCH='amd64' GOOS='linux'; \
;; \
'armhf') \
export GOARCH='arm' GOARM='6' GOOS='linux'; \
;; \
'armv7') \
export GOARCH='arm' GOARM='7' GOOS='linux'; \
;; \
'aarch64') \
export GOARCH='arm64' GOOS='linux'; \
;; \
'x86') \
export GO386='softfloat' GOARCH='386' GOOS='linux'; \
;; \
'ppc64le') \
export GOARCH='ppc64le' GOOS='linux'; \
;; \
's390x') \
export GOARCH='s390x' GOOS='linux'; \
;; \
*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
esac; \
build=; \
if [ -z "$url" ]; then \
# https://github.com/golang/go/issues/38536#issuecomment-616897960
build=1; \
url='https://dl.google.com/go/go1.18.4.src.tar.gz'; \
sha256='4525aa6b0e3cecb57845f4060a7075aafc9ab752bb7b6b4cf8a212d43078e1e4'; \
# the precompiled binaries published by Go upstream are not compatible with Alpine, so we always build from source here 😅
fi; \
\
wget -O go.tgz.asc "$url.asc"; \
wget -O go.tgz "$url"; \
echo "$sha256 *go.tgz" | sha256sum -c -; \
\
# https://github.com/golang/go/issues/14739#issuecomment-324767697
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
# https://www.google.com/linuxrepositories/
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys 'EB4C 1BFD 4F04 2F6D DDCC EC91 7721 F63B D38B 4796'; \
# let's also fetch the specific subkey of that key explicitly that we expect "go.tgz.asc" to be signed by, just to make sure we definitely have it
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys '2F52 8D36 D67B 69ED F998 D857 78BD 6547 3CB3 BD13'; \
gpg --batch --verify go.tgz.asc go.tgz; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME" go.tgz.asc; \
\
tar -C /usr/local -xzf go.tgz; \
rm go.tgz; \
\
if [ -n "$build" ]; then \
apk add --no-cache --virtual .build-deps \
bash \
gcc \
go \
musl-dev \
; \
\
export GOCACHE='/tmp/gocache'; \
\
( \
cd /usr/local/go/src; \
# set GOROOT_BOOTSTRAP + GOHOST* such that we can build Go successfully
export GOROOT_BOOTSTRAP="$(go env GOROOT)" GOHOSTOS="$GOOS" GOHOSTARCH="$GOARCH"; \
./make.bash; \
); \
\
apk del --no-network .build-deps; \
\
# remove a few intermediate / bootstrapping files the official binary release tarballs do not contain
rm -rf \
/usr/local/go/pkg/*/cmd \
/usr/local/go/pkg/bootstrap \
/usr/local/go/pkg/obj \
/usr/local/go/pkg/tool/*/api \
/usr/local/go/pkg/tool/*/go_bootstrap \
/usr/local/go/src/cmd/dist/dist \
"$GOCACHE" \
; \
fi; \
\
apk del --no-network .fetch-deps; \
\
go version
ENV GOPATH /go
ENV PATH $GOPATH/bin:$PATH
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
WORKDIR $GOPATH
RUN apk add --no-cache bash make git gcc libc-dev jq curl dumb-init
RUN cd /tmp && \
git clone https://github.com/go-delve/delve && \
cd delve && \
go install github.com/go-delve/delve/cmd/dlv && \
cd .. && \
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin && \
rm -rf delve && \
chmod -R 777 /go
ENTRYPOINT ["/usr/bin/dumb-init", "--"]

11
1.18/Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM golang:1.18-alpine
RUN apk add --no-cache bash make git gcc libc-dev jq curl dumb-init
RUN cd /tmp && \
git clone https://github.com/go-delve/delve && \
cd delve && \
go install github.com/go-delve/delve/cmd/dlv && \
cd .. && \
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin && \
rm -rf delve && \
chmod -R 777 /go
ENTRYPOINT ["/usr/bin/dumb-init", "--"]

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Pavel Kovalenko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

36
README.md Normal file
View File

@ -0,0 +1,36 @@
# Golang Alpine with additional packages & dumb-init
[![Docker Automated build](https://img.shields.io/docker/automated/Neur0toxine/node-alpine-git.svg)](https://hub.docker.com/r/neur0toxine/golang-alpine-dumb-init/)
[![buildx Status](https://github.com/Neur0toxine/docker-golang-alpine-dumb-init/workflows/buildx/badge.svg)](https://github.com/Neur0toxine/docker-golang-alpine-dumb-init/actions?query=workflow%3Abuildx)
[![Lint Dockerfiles](https://github.com/Neur0toxine/docker-golang-alpine-dumb-init/workflows/Lint%20Dockerfiles/badge.svg)](https://github.com/Neur0toxine/docker-golang-alpine-dumb-init/actions?query=workflow%3A%22Lint+Dockerfiles%22)
A minimal Dockerfile based on Go 1.16, 1.17, 1.18 and alpine with dumb-init and some other useful packages.
## What's included
- Go 1.16
- bash
- make
- git
- ssh
- gcc
- libc-dev
- jq
- curl
- air
- dumb-init
### Available platforms
These Dockerfiles leverage the new `buildx` functionality and offer the following platforms:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/arm/v6
- linux/ppc64le
- linux/s390x
---
Based on solution built by (c) Tim Brust and contributors. Released under the MIT license.