Skip to content

Commit

Permalink
Fix/dockerfile (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-ahn-wm authored May 24, 2024
2 parents cad51f5 + 3e13bd8 commit 3782a59
Show file tree
Hide file tree
Showing 29 changed files with 1,212 additions and 116 deletions.
104 changes: 87 additions & 17 deletions Dockerfile.wemix
Original file line number Diff line number Diff line change
@@ -1,24 +1,94 @@
# builder image
# Stage 1: Build stage
FROM golang:1.19 as builder

FROM ubuntu:focal as base
# Set environment variables
ENV PATH=/usr/local/go/bin:$PATH

SHELL ["/bin/bash", "-c"]
# Update and upgrade the package list
RUN apt-get update && \
apt-get upgrade -q -y

RUN apt-get update -q -y && apt-get upgrade -q -y
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends build-essential ca-certificates curl libjemalloc-dev liblz4-dev libsnappy-dev libzstd-dev libudev-dev git
# Install required packages
RUN apt-get install -y --no-install-recommends \
git \
ca-certificates \
openssl \
make && \
rm -rf /var/lib/apt/lists/*

# golang
RUN curl -sL -o /tmp/go.tar.gz https://dl.google.com/go/$(curl -sL https://golang.org/VERSION?m=text | head -1).linux-amd64.tar.gz && \
pushd /usr/local/ && \
tar xfz /tmp/go.tar.gz && \
cd /usr/local/bin/ && \
ln -sf ../go/bin/* . && \
popd && \
rm /tmp/go.tar.gz
# Define the location for custom certificates
ARG cert_location=/usr/local/share/ca-certificates

RUN apt autoremove && apt autoclean
# Fetch and install certificates for github.com and proxy.golang.org
RUN openssl s_client -showcerts -connect github.com:443 </dev/null 2>/dev/null | \
openssl x509 -outform PEM > ${cert_location}/github.crt && \
openssl s_client -showcerts -connect proxy.golang.org:443 </dev/null 2>/dev/null | \
openssl x509 -outform PEM > ${cert_location}/proxy.golang.crt && \
update-ca-certificates

ENTRYPOINT ["/bin/bash", "-c"]
# Clone the repository, install dependencies, and build the project
RUN git clone https://github.com/wemixarchive/go-wemix.git /go-wemix && \
cd /go-wemix && \
go mod download && \
make

# EOF
# Clean up unnecessary packages and files after building
RUN apt-get remove -y \
git \
ca-certificates \
openssl \
make && \
apt autoremove -y && \
apt-get clean

# Stage 2: Runtime stage
FROM ubuntu:22.04

# Set environment variables
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt

# Update and upgrade the package list
RUN apt-get update && \
apt-get upgrade -q -y

# Install required runtime packages
RUN apt-get install -y --no-install-recommends \
g++ \
libc-dev \
ca-certificates \
bash \
wget && \
update-ca-certificates && \
rm -rf /var/lib/apt/lists/*

# Create directories for wemix
RUN mkdir -p /usr/local/wemix /usr/local/wemix/keystore

# Set environment variables
ENV PATH=/usr/local/wemix/bin:$PATH

# Copy the built binaries and configuration files from the builder stage
COPY --from=builder /go-wemix/build /usr/local/wemix/

# Download and install solc
RUN wget -nv -O /usr/local/bin/solc https://github.com/ethereum/solidity/releases/download/v0.4.24/solc-static-linux && \
chmod a+x /usr/local/bin/solc

# Create new accounts for wemix
RUN bash -c 'for i in 1 2 3 4; do \
/usr/local/wemix/bin/gwemix wemix new-account --password <(echo demo) --out /usr/local/wemix/keystore/account-$i; \
done'

# Clean up unnecessary packages
RUN apt-get remove -y \
g++ \
libc-dev \
wget && \
apt autoremove -y && \
apt-get clean

# Expose necessary ports
EXPOSE 8588 8589 8598

# Set the entrypoint
ENTRYPOINT ["/usr/local/wemix/bin/gwemix"]
6 changes: 3 additions & 3 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"sort"
"strconv"
"strings"
"syscall"
"time"

"github.com/ethereum/go-ethereum/cmd/utils"
Expand All @@ -40,6 +39,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/trie"
"github.com/olekukonko/tablewriter"
"golang.org/x/sys/unix"
"gopkg.in/urfave/cli.v1"
)

Expand Down Expand Up @@ -597,7 +597,7 @@ func importLDBdata(ctx *cli.Context) error {
stop = make(chan struct{})
)
defer stack.Close()
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(interrupt, unix.SIGINT, unix.SIGTERM)
defer signal.Stop(interrupt)
defer close(interrupt)
go func() {
Expand Down Expand Up @@ -693,7 +693,7 @@ func exportChaindata(ctx *cli.Context) error {
stop = make(chan struct{})
)
defer stack.Close()
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(interrupt, unix.SIGINT, unix.SIGTERM)
defer signal.Stop(interrupt)
defer close(interrupt)
go func() {
Expand Down
6 changes: 3 additions & 3 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"sort"
"strconv"
"strings"
"syscall"
"time"

"github.com/elastic/gosigar"
Expand All @@ -45,6 +44,7 @@ import (
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/wemix"
"golang.org/x/sys/unix"

// Force-load the tracer engines to trigger registration
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
Expand Down Expand Up @@ -514,8 +514,8 @@ func limitMaxRss(max int64) {
timer := time.NewTimer(interval)
for {
<-timer.C
rusage := syscall.Rusage{}
err := syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
rusage := unix.Rusage{}
err := unix.Getrusage(unix.RUSAGE_SELF, &rusage)
if err != nil {
log.Error("Getrusage() failed:", "reason", err)
} else {
Expand Down
10 changes: 5 additions & 5 deletions cmd/geth/wemixcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"path/filepath"
"strconv"
"strings"
"syscall"

"github.com/charlanxcc/logrot"
"github.com/ethereum/go-ethereum/accounts/keystore"
Expand All @@ -29,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/wemix/metclient"
"golang.org/x/sys/unix"
"gopkg.in/urfave/cli.v1"
)

Expand Down Expand Up @@ -667,10 +667,10 @@ func logrota(ctx *cli.Context) error {
if err != nil {
return err
}
syscall.Close(syscall.Stdout)
syscall.Close(syscall.Stdout)
syscall.Dup2(int(w.Fd()), syscall.Stdout)
syscall.Dup2(int(w.Fd()), syscall.Stderr)
unix.Close(unix.Stdout)
unix.Close(unix.Stdout)
unix.Dup2(int(w.Fd()), unix.Stdout)
unix.Dup2(int(w.Fd()), unix.Stderr)

go logrot.LogRotate(r, logFile, logSize, logCount)

Expand Down
10 changes: 5 additions & 5 deletions cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"os/signal"
"runtime"
"strings"
"syscall"
"time"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -41,6 +40,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/sys/unix"
"gopkg.in/urfave/cli.v1"
)

Expand Down Expand Up @@ -74,7 +74,7 @@ func StartNode(ctx *cli.Context, stack *node.Node, isConsole bool) {
}
go func() {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(sigc, unix.SIGINT, unix.SIGTERM)
defer signal.Stop(sigc)

minFreeDiskSpace := 2 * ethconfig.Defaults.TrieDirtyCache // Default 2 * 256Mb
Expand Down Expand Up @@ -105,7 +105,7 @@ func StartNode(ctx *cli.Context, stack *node.Node, isConsole bool) {
// However, SIGTERM still shuts down the node.
for {
sig := <-sigc
if sig == syscall.SIGTERM {
if sig == unix.SIGTERM {
shutdown()
return
}
Expand All @@ -126,7 +126,7 @@ func monitorFreeDiskSpace(sigc chan os.Signal, path string, freeDiskSpaceCritica
}
if freeSpace < freeDiskSpaceCritical {
log.Error("Low disk space. Gracefully shutting down Geth to prevent database corruption.", "available", common.StorageSize(freeSpace))
sigc <- syscall.SIGTERM
sigc <- unix.SIGTERM
break
} else if freeSpace < 2*freeDiskSpaceCritical {
log.Warn("Disk space is running low. Geth will shutdown if disk space runs below critical level.", "available", common.StorageSize(freeSpace), "critical_level", common.StorageSize(freeDiskSpaceCritical))
Expand All @@ -140,7 +140,7 @@ func ImportChain(chain *core.BlockChain, fn string) error {
// If a signal is received, the import will stop at the next batch.
interrupt := make(chan os.Signal, 1)
stop := make(chan struct{})
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(interrupt, unix.SIGINT, unix.SIGTERM)
defer signal.Stop(interrupt)
defer close(interrupt)
go func() {
Expand Down
18 changes: 9 additions & 9 deletions common/fdlimit/fdlimit_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package fdlimit

import "syscall"
import "golang.org/x/sys/unix"

// This file is largely identical to fdlimit_unix.go,
// but Rlimit fields have type int64 on *BSD so it needs
Expand All @@ -29,19 +29,19 @@ import "syscall"
// to the maximum hard-limit allowed by the OS.
func Raise(max uint64) (uint64, error) {
// Get the current limit
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
var limit unix.Rlimit
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
// Try to update the limit to the max allowance
limit.Cur = limit.Max
if limit.Cur > int64(max) {
limit.Cur = int64(max)
}
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
return uint64(limit.Cur), nil
Expand All @@ -50,8 +50,8 @@ func Raise(max uint64) (uint64, error) {
// Current retrieves the number of file descriptors allowed to be opened by this
// process.
func Current() (int, error) {
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
var limit unix.Rlimit
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
return int(limit.Cur), nil
Expand All @@ -60,8 +60,8 @@ func Current() (int, error) {
// Maximum retrieves the maximum number of file descriptors this process is
// allowed to request for itself.
func Maximum() (int, error) {
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
var limit unix.Rlimit
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
return int(limit.Max), nil
Expand Down
18 changes: 9 additions & 9 deletions common/fdlimit/fdlimit_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package fdlimit

import "syscall"
import "golang.org/x/sys/unix"

// hardlimit is the number of file descriptors allowed at max by the kernel.
const hardlimit = 10240
Expand All @@ -26,20 +26,20 @@ const hardlimit = 10240
// Returns the size it was set to (may differ from the desired 'max')
func Raise(max uint64) (uint64, error) {
// Get the current limit
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
var limit unix.Rlimit
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
// Try to update the limit to the max allowance
limit.Cur = limit.Max
if limit.Cur > max {
limit.Cur = max
}
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
// MacOS can silently apply further caps, so retrieve the actually set limit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
return limit.Cur, nil
Expand All @@ -48,8 +48,8 @@ func Raise(max uint64) (uint64, error) {
// Current retrieves the number of file descriptors allowed to be opened by this
// process.
func Current() (int, error) {
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
var limit unix.Rlimit
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
return int(limit.Cur), nil
Expand All @@ -59,8 +59,8 @@ func Current() (int, error) {
// allowed to request for itself.
func Maximum() (int, error) {
// Retrieve the maximum allowed by dynamic OS limits
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
var limit unix.Rlimit
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
// Cap it to OPEN_MAX (10240) because macos is a special snowflake
Expand Down
Loading

0 comments on commit 3782a59

Please sign in to comment.