Skip to content

Commit

Permalink
Update Dockerfile (#85)
Browse files Browse the repository at this point in the history
* create directory if not exist, use os instead of iotuil

* new dockerfile
  • Loading branch information
tiero authored Feb 9, 2024
1 parent ddbbdd3 commit dd0b884
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
26 changes: 9 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# first image used to build the sources
FROM golang:1.18-buster AS builder
FROM golang:1.20-buster AS builder

ARG VERSION
ARG COMMIT
Expand All @@ -17,33 +17,25 @@ RUN go build -ldflags="-X 'main.version=${VERSION}' -X 'main.commit=${COMMIT}' -
# Second image, running the oceand executable
FROM debian:buster-slim

# $USER name, and data $DIR to be used in the `final` image
ARG USER=ocean
ARG DIR=/home/ocean
# Set the working directory inside the container
WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates

COPY --from=builder /app/bin/* /usr/local/bin/
COPY --from=builder /app/bin/* /app
COPY --from=builder /app/internal/infrastructure/storage/db/postgres/migration/* /

ENV OCEAN_DB_MIGRATION_PATH=file://

# NOTE: Default GID == UID == 1000
RUN adduser --disabled-password \
--home "$DIR/" \
--gecos "" \
"$USER"
USER $USER

# Prevents `VOLUME $DIR/.oceand/` being created as owned by `root`
RUN mkdir -p "$DIR/.oceand/"
ENV OCEAN_DATADIR=/app/data/oceand
ENV OCEAN_CLI_DATADIR=/app/data/ocean
ENV PATH="/app:${PATH}"

# Expose volume containing all `oceand` data
VOLUME $DIR/.oceand/
VOLUME /app/data

# Expose ports of grpc server and profiler
EXPOSE 18000
EXPOSE 18001

ENTRYPOINT [ "oceand" ]
ENTRYPOINT ["oceand"]

14 changes: 11 additions & 3 deletions cmd/ocean/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
Expand Down Expand Up @@ -92,7 +91,7 @@ func getClientConn() (*grpc.ClientConn, error) {
}

func getState() (map[string]string, error) {
file, err := ioutil.ReadFile(statePath)
file, err := os.ReadFile(statePath)
if err != nil {
if !os.IsNotExist(err) {
return nil, err
Expand Down Expand Up @@ -121,8 +120,17 @@ func setState(partialState map[string]string) error {
}

func writeState(state map[string]string) error {

dir := filepath.Dir(statePath)
if _, err := os.Stat(dir); os.IsNotExist(err) {
err = os.MkdirAll(dir, 0755)
if err != nil {
return fmt.Errorf("failed to create directory: %v", err)
}
}

buf, _ := json.MarshalIndent(state, "", " ")
if err := ioutil.WriteFile(statePath, buf, 0755); err != nil {
if err := os.WriteFile(statePath, buf, 0755); err != nil {
return fmt.Errorf("writing to file: %w", err)
}

Expand Down

0 comments on commit dd0b884

Please sign in to comment.