adding a scratch container. integrating with btcd.
This commit is contained in:
@@ -35,21 +35,46 @@ func strPtr(str string) *string { return &str }
|
||||
|
||||
var buildConfigurations = []docker.BuildConfiguration{
|
||||
//docker.BuildConfiguration{
|
||||
// Name: defaultRepositoryName + "/" + "indra",
|
||||
// ContextFilePath: "/tmp/indra-" + indra.SemVer + ".tar",
|
||||
// Name: defaultRepositoryName + "/" + "scratch",
|
||||
// ContextFilePath: "/tmp/scratch.tar",
|
||||
// BuildOpts: types.ImageBuildOptions{
|
||||
// Dockerfile: "docker/indra/Dockerfile",
|
||||
// Dockerfile: "docker/scratch/Dockerfile",
|
||||
// Tags: []string{
|
||||
// indra.SemVer,
|
||||
// "latest",
|
||||
// },
|
||||
// BuildArgs: map[string]*string{},
|
||||
// BuildArgs: map[string]*string{
|
||||
// "base_image": strPtr("busybox"),
|
||||
// },
|
||||
// SuppressOutput: false,
|
||||
// Remove: true,
|
||||
// ForceRemove: true,
|
||||
// PullParent: true,
|
||||
// },
|
||||
//},
|
||||
docker.BuildConfiguration{
|
||||
Name: defaultRepositoryName + "/" + "btcd",
|
||||
ContextFilePath: "/tmp/btcd.tar",
|
||||
BuildOpts: types.ImageBuildOptions{
|
||||
Dockerfile: "docker/btcd/Dockerfile",
|
||||
Tags: []string{
|
||||
"v0.23.4",
|
||||
"latest",
|
||||
},
|
||||
BuildArgs: map[string]*string{
|
||||
"base_image": strPtr(defaultBuildContainer),
|
||||
"target_image": strPtr("indralabs/scratch:latest"),
|
||||
// This argument is the tag fetched by git
|
||||
// It MUST be updated alongside the tag above
|
||||
"git_repository": strPtr("github.com/btcsuite/btcd"),
|
||||
"git_tag": strPtr("v0.23.4"),
|
||||
},
|
||||
SuppressOutput: false,
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
PullParent: true,
|
||||
},
|
||||
},
|
||||
//docker.BuildConfiguration{
|
||||
// Name: defaultRepositoryName + "/" + "lnd",
|
||||
// ContextFilePath: "/tmp/lnd.tar",
|
||||
@@ -70,27 +95,22 @@ var buildConfigurations = []docker.BuildConfiguration{
|
||||
// PullParent: true,
|
||||
// },
|
||||
//},
|
||||
docker.BuildConfiguration{
|
||||
Name: defaultRepositoryName + "/" + "btcd",
|
||||
ContextFilePath: "/tmp/btcd.tar",
|
||||
BuildOpts: types.ImageBuildOptions{
|
||||
Dockerfile: "docker/btcd/Dockerfile",
|
||||
Tags: []string{
|
||||
"v0.23.4",
|
||||
"latest",
|
||||
},
|
||||
BuildArgs: map[string]*string{
|
||||
// This argument is the tag fetched by git
|
||||
// It MUST be updated alongside the tag above
|
||||
"git_repository": strPtr("github.com/btcsuite/btcd"),
|
||||
"git_tag": strPtr("v0.23.4"),
|
||||
},
|
||||
SuppressOutput: false,
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
PullParent: true,
|
||||
},
|
||||
},
|
||||
//docker.BuildConfiguration{
|
||||
// Name: defaultRepositoryName + "/" + "indra",
|
||||
// ContextFilePath: "/tmp/indra-" + indra.SemVer + ".tar",
|
||||
// BuildOpts: types.ImageBuildOptions{
|
||||
// Dockerfile: "docker/indra/Dockerfile",
|
||||
// Tags: []string{
|
||||
// indra.SemVer,
|
||||
// "latest",
|
||||
// },
|
||||
// BuildArgs: map[string]*string{},
|
||||
// SuppressOutput: false,
|
||||
// Remove: true,
|
||||
// ForceRemove: true,
|
||||
// PullParent: true,
|
||||
// },
|
||||
//},
|
||||
}
|
||||
|
||||
var commands = &cmds.Command{
|
||||
|
||||
@@ -1,37 +1,23 @@
|
||||
FROM golang:1.19.4 AS builder
|
||||
|
||||
# User/Group definition
|
||||
ENV USER=btcd GROUP=btcd UID=8333 GID=8333
|
||||
ARG base_image="golang"
|
||||
ARG target_image="indralabs/scratch"
|
||||
|
||||
## Create a user/group to be migrated to the target container
|
||||
RUN addgroup ${GROUP} --gid ${GID} \
|
||||
&& adduser \
|
||||
--disabled-password \
|
||||
--gecos "" \
|
||||
--home "/var/btcd" \
|
||||
--shell "/sbin/nologin" \
|
||||
#--no-create-home \
|
||||
--uid "${UID}" \
|
||||
--gid "${GID}" \
|
||||
"${USER}"
|
||||
# ---
|
||||
# Build Process
|
||||
# ---
|
||||
|
||||
# Create config/data directories
|
||||
RUN set -ex \
|
||||
&& mkdir -pv /var/btcd \
|
||||
&& mkdir -pv /var/run/btcd \
|
||||
&& mkdir -pv /etc/btcd \
|
||||
&& mkdir -pv /etc/btcd/keys
|
||||
FROM ${base_image} AS builder
|
||||
|
||||
# Pass a tag, branch or a commit using build-arg. This allows a docker
|
||||
# image to be built from a specified Git state. The default image
|
||||
# will use the Git tip of master by default.
|
||||
# Get the repo and build
|
||||
ARG git_repository="github.com/indra-labs/btcd"
|
||||
ARG git_tag="master"
|
||||
|
||||
# Install dependencies and build the binaries.
|
||||
RUN git clone "https://"${git_repository} /go/src/${git_repository} \
|
||||
&& cd /go/src/${git_repository} \
|
||||
&& git checkout ${git_tag}
|
||||
RUN git clone "https://"${git_repository} /go/src/${git_repository}
|
||||
|
||||
WORKDIR $GOPATH/src/${git_repository}
|
||||
|
||||
RUN git checkout ${git_tag}
|
||||
|
||||
# Source/Target release defaults
|
||||
ARG ARCH=amd64
|
||||
@@ -41,35 +27,26 @@ ENV GO111MODULE=on GOOS=linux
|
||||
|
||||
WORKDIR $GOPATH/src/${git_repository}
|
||||
|
||||
RUN cp sample-btcd.conf /tmp/btcd.conf
|
||||
|
||||
RUN set -ex \
|
||||
&& CGO_ENABLED=0 go build --ldflags '-w -s' -o /bin/btcd . \
|
||||
&& CGO_ENABLED=0 go build --ldflags '-w -s' -o /bin/ ./cmd/...
|
||||
|
||||
# Copy the sample config file
|
||||
RUN cp /go/src/${git_repository}/sample-btcd.conf /etc/btcd/btcd.conf
|
||||
&& CGO_ENABLED=0 go build --ldflags '-w -s' -o /tmp/bin/btcd . \
|
||||
&& CGO_ENABLED=0 go build --ldflags '-w -s' -o /tmp/bin/ ./cmd/...
|
||||
|
||||
# ---
|
||||
# Configure and Build the target container
|
||||
# Target Configuration
|
||||
# ---
|
||||
|
||||
FROM scratch
|
||||
FROM indralabs/scratch:latest
|
||||
|
||||
# Migrate User/Group to target
|
||||
COPY --from=builder /etc/passwd /etc/passwd
|
||||
COPY --from=builder /etc/group /etc/group
|
||||
COPY --from=builder /etc/btcd /etc/btcd
|
||||
## Migrate the binaries and storage folder
|
||||
|
||||
# Migrate the binaries and storage folder
|
||||
COPY --from=builder /bin /bin
|
||||
COPY --from=builder --chown=btcd:btcd /var/btcd /var/btcd
|
||||
COPY --from=builder --chown=btcd:btcd /var/run/btcd /var/run/btcd
|
||||
COPY --from=builder /tmp/btcd.conf /etc/btcd/btcd.conf
|
||||
COPY --from=builder /tmp/bin /bin
|
||||
|
||||
# Enable the indra user
|
||||
# Enable the btcd user
|
||||
USER btcd:btcd
|
||||
|
||||
# ENV defaults
|
||||
# ENV IND_LOGFILEPATH=""
|
||||
|
||||
# Set the data volumes
|
||||
#VOLUME ["/etc/btcd"]
|
||||
#VOLUME ["/var/btcd"]
|
||||
@@ -78,5 +55,4 @@ USER btcd:btcd
|
||||
# :8334 btcd RPC port
|
||||
EXPOSE 8333 8334
|
||||
|
||||
ENTRYPOINT ["/bin/btcd", "--configfile=/etc/btcd/btcd.conf", "--datadir=/var/btcd", "--rpckey=/etc/btcd/keys/rpc.key", "--rpccert=/etc/btcd/keys/rpc.cert"]
|
||||
CMD ["--listen=0.0.0.0:8333", "--rpclisten=0.0.0.0:8334"]
|
||||
ENTRYPOINT ["/bin/btcd", "--configfile=/etc/btcd/btcd.conf", "--datadir=/var/btcd", "--logdir=/var/btcd", "--rpckey=/etc/btcd/keys/rpc.key", "--rpccert=/etc/btcd/keys/rpc.cert", "--listen=0.0.0.0:8333", "--rpclisten=0.0.0.0:8334"]
|
||||
|
||||
134
docker/scratch/Dockerfile
Normal file
134
docker/scratch/Dockerfile
Normal file
@@ -0,0 +1,134 @@
|
||||
|
||||
ARG base_image=busybox
|
||||
|
||||
FROM ${base_image} as base
|
||||
|
||||
RUN set -ex && echo "creating root filesystem" \
|
||||
&& mkdir -pv /tmp/root-fs \
|
||||
&& mkdir -pv /tmp/root-fs/etc \
|
||||
&& mkdir -pv /tmp/root-fs/var \
|
||||
&& mkdir -pv /tmp/root-fs/bin
|
||||
|
||||
RUN set -ex && echo "checking root filesystem" \
|
||||
&& ls -hal /tmp/root-fs \
|
||||
&& ls -hal /tmp/root-fs/etc \
|
||||
&& ls -hal /tmp/root-fs/var \
|
||||
&& ls -hal /tmp/root-fs/bin
|
||||
|
||||
##
|
||||
## Users and Groups
|
||||
##
|
||||
|
||||
RUN set -ex && echo "adding users and groups" \
|
||||
&& echo "btcd:*:::::::" >> /etc/shadow \
|
||||
&& echo "btcd:x:8333:" >> /etc/group \
|
||||
&& echo "btcd:x:8333:8333:btcd:/var/btcd:/sbin/false" >> /etc/passwd \
|
||||
&& echo "lnd:*:::::::" >> /etc/shadow \
|
||||
&& echo "lnd:x:9735:" >> /etc/group \
|
||||
&& echo "lnd:x:9735:9735:lnd:/var/lnd:/sbin/false" >> /etc/passwd \
|
||||
&& echo "indra:*:::::::" >> /etc/shadow \
|
||||
&& echo "indra:x:8337:" >> /etc/group \
|
||||
&& echo "indra:x:8337:8337:indra:/var/indra:/sbin/false" >> /etc/passwd
|
||||
|
||||
RUN set -ex && echo "checking users and groups" \
|
||||
&& cat /etc/shadow \
|
||||
&& cat /etc/group \
|
||||
&& cat /etc/passwd
|
||||
|
||||
RUN set -ex && echo "copying users and groups to root filesystem" \
|
||||
&& cp -p /etc/shadow /tmp/root-fs/etc/shadow \
|
||||
&& cp -p /etc/group /tmp/root-fs/etc/group \
|
||||
&& cp -p /etc/passwd /tmp/root-fs/etc/passwd
|
||||
|
||||
# DEBUG
|
||||
RUN set -ex && echo "checking users and groups to root filesystem" \
|
||||
&& ls -hal /tmp/root-fs/etc \
|
||||
&& cat /tmp/root-fs/etc/shadow \
|
||||
&& cat /tmp/root-fs/etc/passwd \
|
||||
&& cat /tmp/root-fs/etc/group
|
||||
|
||||
##
|
||||
## Configuration and Data directories
|
||||
##
|
||||
|
||||
RUN set -ex && echo "adding and permissioning /etc directories" \
|
||||
&& mkdir -pv /etc/btcd && chmod 755 /etc/btcd \
|
||||
&& mkdir -pv /etc/btcd/keys && chmod 750 /etc/btcd/keys && chown btcd:btcd /etc/btcd/keys \
|
||||
&& mkdir -pv /etc/lnd && chmod 755 /etc/lnd \
|
||||
&& mkdir -pv /etc/lnd/keys && chmod 750 /etc/lnd/keys && chown lnd:lnd /etc/lnd/keys \
|
||||
&& mkdir -pv /etc/indra && chmod 755 /etc/indra
|
||||
|
||||
RUN set -ex && echo "copying /etc directories to root filesystem" \
|
||||
&& cp -rp /etc/btcd /tmp/root-fs/etc/btcd \
|
||||
&& cp -rp /etc/lnd /tmp/root-fs/etc/lnd \
|
||||
&& cp -rp /etc/indra /tmp/root-fs/etc/indra
|
||||
|
||||
# DEBUG
|
||||
RUN set -ex && echo "checking /etc directories on root filesystem" \
|
||||
&& ls -hal /tmp/root-fs/etc \
|
||||
&& ls -hal /tmp/root-fs/etc/btcd \
|
||||
&& ls -hal /tmp/root-fs/etc/btcd/keys \
|
||||
&& ls -hal /tmp/root-fs/etc/lnd \
|
||||
&& ls -hal /tmp/root-fs/etc/lnd/keys \
|
||||
&& ls -hal /tmp/root-fs/etc/indra
|
||||
|
||||
RUN set -ex && echo "adding and permissioning /var directories" \
|
||||
&& mkdir -pv /var/btcd && chmod 750 /var/btcd && chown btcd:btcd /var/btcd \
|
||||
&& mkdir -pv /var/btcd/.btcd && chmod 750 /var/btcd/.btcd && chown btcd:btcd /var/btcd/.btcd \
|
||||
&& mkdir -pv /var/lnd && chmod 750 /var/lnd && chown lnd:lnd /var/lnd \
|
||||
&& mkdir -pv /var/lnd/.lnd && chmod 750 /var/lnd/.lnd && chown lnd:lnd /var/lnd/.lnd \
|
||||
&& mkdir -pv /var/indra && chmod 750 /var/indra && chown indra:indra /var/indra
|
||||
|
||||
RUN set -ex && echo "copying /var directories to root filesystem" \
|
||||
&& cp -rp /var/btcd /tmp/root-fs/var/btcd \
|
||||
&& cp -rp /var/lnd /tmp/root-fs/var/lnd \
|
||||
&& cp -rp /var/indra /tmp/root-fs/var/indra
|
||||
|
||||
# DEBUG
|
||||
RUN set -ex && echo "checking /var directories on root filesystem" \
|
||||
&& ls -hal /tmp/root-fs/var \
|
||||
&& ls -hal /tmp/root-fs/var/btcd \
|
||||
&& ls -hal /tmp/root-fs/var/btcd/.btcd \
|
||||
&& ls -hal /tmp/root-fs/var/lnd \
|
||||
&& ls -hal /tmp/root-fs/var/lnd/.lnd \
|
||||
&& ls -hal /tmp/root-fs/var/indra
|
||||
|
||||
WORKDIR /tmp/root-fs
|
||||
|
||||
RUN set -ex && echo "building root-fs tarball" \
|
||||
&& tar -cvzf /tmp/root-fs.tgz . \
|
||||
&& rm -rf /tmp/root-fs \
|
||||
&& ls -hal /tmp
|
||||
|
||||
RUN set -ex && tar -xzvf /tmp/root-fs.tgz \
|
||||
&& ls -hal /tmp \
|
||||
&& ls -hal /tmp/root-fs \
|
||||
&& ls -hal /tmp/root-fs/etc \
|
||||
&& ls -hal /tmp/root-fs/etc/btcd \
|
||||
|
||||
##
|
||||
## Base Image
|
||||
##
|
||||
|
||||
#
|
||||
# Note: We CANNOT use the scratch container to build the our scratch image.
|
||||
#
|
||||
# When using the COPY command between container, docker does not preserve permissions.
|
||||
# Instead, we will opt for generating a root-fs on the build image and extracting it as a tarball.
|
||||
#
|
||||
|
||||
#FROM scratch
|
||||
#
|
||||
## Migrate over users and groups
|
||||
#COPY --from=base /etc/passwd /etc/passwd
|
||||
#COPY --from=base /etc/group /etc/group
|
||||
#
|
||||
## Configuration
|
||||
#COPY --from=base /etc/btcd /etc/btcd
|
||||
#COPY --from=base /etc/lnd /etc/lnd
|
||||
#COPY --from=base /etc/indra /etc/indra
|
||||
#
|
||||
### Data
|
||||
#COPY --from=base --chown=btcd:btcd /var/btcd /var/btcd
|
||||
#COPY --from=base --chown=lnd:lnd /var/lnd /var/lnd
|
||||
#COPY --from=base --chown=indra:indra /var/indra /var/indra
|
||||
9
docker/scratch/build.sh
Executable file
9
docker/scratch/build.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
docker build -t indralabs/scratch-builder .
|
||||
|
||||
docker run --rm -it --volume=${PWD}/tmp:/output indralabs/scratch-builder cp /tmp/root-fs.tgz /output
|
||||
|
||||
docker image import tmp/root-fs.tgz indralabs/scratch
|
||||
|
||||
docker push indralabs/scratch:latest
|
||||
1
docker/scratch/tmp/.gitignore
vendored
Normal file
1
docker/scratch/tmp/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
root-fs.tgz
|
||||
0
docker/scratch/tmp/.gitkeep
Normal file
0
docker/scratch/tmp/.gitkeep
Normal file
Reference in New Issue
Block a user