-
Notifications
You must be signed in to change notification settings - Fork 79
/
Dockerfile
58 lines (41 loc) · 1.92 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Building this Dockerfile executes a full build of the Recovery Tool, cross-compiling inside
# the container. The resulting executable is copied to the output directory using Docker BuildKit.
# You need to pass 3 parameters via --build-arg:
# 1. `os` : the GOOS env var -- `linux`, `windows` or `darwin`.
# 2. `arch`: the GOARCH env var -- `386` or `amd64` (note that darwin/386 is not a thing).
# 3. `cc` : the CC env var -- a C compiler for CGO to use, empty to use the default.
# 4. `out` : the name of the resulting executable, placed in the output directory on the host.
# For example, to build a linux/386 binary into `bin/rt`:
# docker build . --output bin --build-arg os=linux --build-arg arch=386 --build-arg out=rt
# Note that the --output <dir> flag refers to the host, outside the container.
# --------------------------------------------------------------------------------------------------
FROM ubuntu:22.04 AS rtool-build-base
# Avoid prompts during package installation:
ENV DEBIAN_FRONTEND="noninteractive"
# Upgrade indices:
RUN apt-get update
# Install the various compilers we're going to use, with specific versions:
RUN apt-get install -y \
golang-1.18-go=1.18.1-1ubuntu1 \
gcc-mingw-w64=10.3.0-14ubuntu1+24.3 \
gcc-multilib=4:11.2.0-1ubuntu1 \
git=1:2.34.1-1ubuntu1
# Copy the source code into the container:
WORKDIR /src
COPY . .
RUN /bin/bash
# --------------------------------------------------------------------------------------------------
FROM rtool-build-base AS rtool-build
ARG os
ARG arch
ARG cc
# Enable and configure C support:
ENV CGO_ENABLED=1
ENV GO386=softfloat
# Do the thing:
RUN env GOOS=${os} GOARCH=${arch} CC=${cc} /usr/lib/go-1.18/bin/go build -mod=vendor -a -trimpath -o /out .
# --------------------------------------------------------------------------------------------------
FROM scratch
ARG out
# Copy the resulting executable back to the host:
COPY --from=rtool-build /out ${out}