Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit cda6c82

Browse files
authored
Merge pull request #3 from crazy-max/ci
Update dockerfile and setup CI
2 parents 11fcb5e + b353aba commit cda6c82

File tree

7 files changed

+173
-284
lines changed

7 files changed

+173
-284
lines changed

.github/workflows/build.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: build
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'master'
8+
- 'v[0-9]*'
9+
tags:
10+
- 'v*'
11+
pull_request:
12+
branches:
13+
- 'master'
14+
- 'v[0-9]*'
15+
16+
env:
17+
# FIXME: Use docker/dockerfile when merged
18+
REPO_SLUG: "crazymax/dockerfile"
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
channel:
27+
- mainline
28+
- labs
29+
steps:
30+
-
31+
name: Checkout
32+
uses: actions/checkout@v2
33+
-
34+
name: Docker meta
35+
id: meta
36+
uses: docker/metadata-action@v3
37+
with:
38+
images: |
39+
${{ env.REPO_SLUG }}
40+
tags: |
41+
type=semver,pattern={{version}},enable=${{ matrix.channel == 'mainline' }}
42+
type=semver,pattern={{version}},suffix=-${{ matrix.channel }},enable=${{ matrix.channel != 'mainline' }}
43+
type=ref,event=branch,enable=${{ matrix.channel == 'mainline' }}
44+
type=ref,event=branch,suffix=-${{ matrix.channel }},enable=${{ matrix.channel != 'mainline' }}
45+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') && matrix.channel == 'mainline' }}
46+
type=raw,value=latest,suffix=-${{ matrix.channel }},enable=${{ startsWith(github.ref, 'refs/tags/') && matrix.channel != 'mainline' }}
47+
type=ref,event=pr
48+
bake-target: meta-helper
49+
flavor: |
50+
latest=false
51+
-
52+
name: Set up QEMU
53+
uses: docker/setup-qemu-action@v1
54+
-
55+
name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v1
57+
-
58+
name: Login to DockerHub
59+
if: github.event_name != 'pull_request'
60+
uses: docker/login-action@v1
61+
with:
62+
username: ${{ secrets.DOCKERHUB_USERNAME }}
63+
password: ${{ secrets.DOCKERHUB_TOKEN }}
64+
-
65+
name: Build image
66+
uses: docker/bake-action@v1
67+
with:
68+
files: |
69+
./docker-bake.hcl
70+
${{ steps.meta.outputs.bake-file }}
71+
targets: image-cross
72+
push: ${{ github.event_name != 'pull_request' }}

Dockerfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# syntax=docker/dockerfile:1-labs
2+
3+
ARG GO_VERSION=1.17
4+
ARG XX_VERSION=1.1.0
5+
ARG CHANNEL
6+
7+
# xx is a helper for cross-compilation
8+
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
9+
10+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
11+
COPY --from=xx / /
12+
RUN apk add --no-cache file git
13+
ENV CGO_ENABLED=0
14+
ENV GOFLAGS=-mod=vendor
15+
WORKDIR /src
16+
17+
FROM base AS version
18+
ARG CHANNEL
19+
RUN --mount=target=. <<EOT
20+
channel=$CHANNEL
21+
suffix=""
22+
buildtags=""
23+
if [ -z "$channel" ]; then
24+
channel="mainline"
25+
fi
26+
if [ "$channel" != "mainline" ]; then
27+
suffix="-$channel"
28+
fi
29+
if [ -f "./release/$channel/tags" ]; then
30+
buildtags="$(cat ./release/$channel/tags)"
31+
fi
32+
PKG=github.com/docker/dockerfile
33+
VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags)$suffix
34+
REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
35+
echo "-X main.Version=${VERSION} -X main.Revision=${REVISION} -X main.Package=${PKG}" | tee /tmp/.ldflags
36+
echo -n "${VERSION}" | tee /tmp/.version
37+
echo -n "${buildtags}" | tee /tmp/.buildtags
38+
EOT
39+
40+
FROM base AS build
41+
ARG LDFLAGS="-w -s"
42+
ARG TARGETPLATFORM
43+
RUN --mount=type=bind,target=. \
44+
--mount=type=cache,target=/root/.cache \
45+
--mount=type=cache,target=/go/pkg/mod \
46+
--mount=type=bind,from=version,source=/tmp/.ldflags,target=/tmp/.ldflags \
47+
--mount=type=bind,from=version,source=/tmp/.buildtags,target=/tmp/.buildtags <<EOT
48+
(set -x ; xx-go build -o /dockerfile-frontend -ldflags "-d $(cat /tmp/.ldflags) ${LDFLAGS}" -tags "$(cat /tmp/.buildtags) netgo static_build osusergo" ./cmd/dockerfile-frontend)
49+
xx-verify --static /dockerfile-frontend
50+
EOT
51+
52+
FROM scratch
53+
LABEL moby.buildkit.frontend.network.none="true"
54+
LABEL moby.buildkit.frontend.caps="moby.buildkit.frontend.inputs,moby.buildkit.frontend.subrequests,moby.buildkit.frontend.contexts"
55+
COPY --from=build /dockerfile-frontend /bin/dockerfile-frontend
56+
ENTRYPOINT ["/bin/dockerfile-frontend"]

cmd/dockerfile-frontend/Dockerfile

Lines changed: 0 additions & 50 deletions
This file was deleted.

cmd/dockerfile-frontend/hack/check-daily-outdated

Lines changed: 0 additions & 48 deletions
This file was deleted.

cmd/dockerfile-frontend/hack/detect

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)