반응형

golang을 최소 설치를 했더니 귀찮다.

FROM golang:alpine

WORKDIR /app

COPY . ./

RUN go mod download
RUN go mod tidy
RUN go build -o main .

# TimeZone 설정
RUN apk --no-cache add tzdata && \
    cp /usr/share/zoneinfo/Asia/Seoul /etc/localtime && \
    echo "Asia/Seoul" > /etc/timezone \
    apk del tzdata

CMD ["./main", "1"]
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /App

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out


# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /App
COPY --from=build-env /App/out .

# TimeZone 설정
ENV TZ Asia/Seoul
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone


ENTRYPOINT ["dotnet", "AnomalyDetection.dll"]
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /App

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /App
COPY --from=build-env /App/out .

# TimeZone 설정
ENV TZ Asia/Seoul
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone


ENTRYPOINT ["dotnet", "Aru.dll"]
version: '3.3'
services:
  aru_collector:
    image: 'aru_collector'
    volumes:
    - /mnt/d/Data/Aru:/var/pos
    - /mnt/d/ML/Data:/var/data    
    - /mnt/d/data/AruTrigger:/var/trigger    
    environment:
      ENVIRONMENT: linux
    links:
    - "PostgreSQL"
  aru_anomaly_detection:
    image: 'aru_anomaly_detection'
    volumes:
    - /mnt/d/ML/Data:/var/data    
    - /mnt/d/data/AruTrigger:/var/trigger    
    environment:
      ENVIRONMENT: linux
    links:
    - "PostgreSQL"  
  aru:
    image: 'aru'
    volumes:
    - /mnt/d/ML/Data:/var/data    
    - /mnt/d/data/AruTrigger:/var/trigger    
    environment:
      ENVIRONMENT: linux
    network_mode: "host"
  PostgreSQL:
    image: postgres
    environment:
      POSTGRES_PASSWORD: "test"          
    ports:
    - 5432:5432
    volumes:
    - /home/postgreSQL:/var/lib/postgresql/data
    shm_size: 1g

'프로그래밍' 카테고리의 다른 글

docker network mode  (0) 2022.12.06
Postgresql Last Insert Id 얻기  (0) 2022.12.01
golang docker 말기  (0) 2022.11.24
golang 공유 자원 사용하기  (0) 2022.11.03
golang 간단한 pg 라이브러리  (0) 2022.11.02
반응형

Dockerfile

FROM golang:alpine AS builder
ENV GO111MODULE=on \
    CGO_ENABLED=0 \
    GOOS=linux \
    GOARCH=amd64

WORKDIR /build
COPY go.mod go.sum main.go ./
COPY Conf_Linux.json ./Conf.json
COPY dao ./dao
COPY model ./model
RUN go mod download
RUN go mod tidy
RUN go build -o main .
WORKDIR /dist
RUN cp /build/main .

FROM scratch
COPY --from=builder /dist/main .
ENTRYPOINT ["/main"]

docker no cache build

docker build --no-cache -t aru_collector .

docker root 그룹 추가 및 적용

sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
반응형

golang으로 작업할 때

 

공유 자원을 defer로 정리하는 경우가 있는데

이러면 버퍼가 풀 날 수 있다

그럴 때는 걍 2번 닫으면 된다.

 

    db := e.PostgerSQL.Open()
    defer db.Close()

    accountInfo.Insert(db)
    db.Close()

'프로그래밍' 카테고리의 다른 글

이번에 작업한 도커파일  (0) 2022.11.28
golang docker 말기  (0) 2022.11.24
golang 간단한 pg 라이브러리  (0) 2022.11.02
golnag으로 pg에 간단히 insert 하는 법  (0) 2022.11.02
postgresql wsl2에 설치  (0) 2022.10.26
반응형
type PostgerSQL struct {
    ConnectionString string
}

func (s *PostgerSQL) Init(e *EndPoint) {
    s.ConnectionString = fmt.Sprintf("host=%s user=%s password=%s dbname=%s sslmode=disable", e.PostgreSQL.Host, e.PostgreSQL.USER, e.PostgreSQL.PASSWORD, e.PostgreSQL.DATABASE)
}

func (s *PostgerSQL) Open() *sql.DB {
    db, err := sql.Open("postgres", s.ConnectionString)
    if err != nil {
        log.Panic().Stack().Err(err).Msg("Open")
    }
    db.SetMaxOpenConns(200)
    db.SetMaxIdleConns(2)
    return db
}

'프로그래밍' 카테고리의 다른 글

golang docker 말기  (0) 2022.11.24
golang 공유 자원 사용하기  (0) 2022.11.03
golnag으로 pg에 간단히 insert 하는 법  (0) 2022.11.02
postgresql wsl2에 설치  (0) 2022.10.26
vscode perfoce 플러그인 연동  (0) 2022.10.21
반응형
func (a *Account) Insert(db *sql.DB) {
    now := time.Now()
    sql_statement := "INSERT INTO account (account_id, device_model, memory_size, created_at) VALUES ($1, $2, $3, $4);"
    _, err := db.Exec(sql_statement, a.AccountId, a.DeviecModel, a.MemorySize, now)
    if err != nil {
        sql_statement = "UPDATE account SET device_model = $1, memory_size = $2, created_at = $3 WHERE account_id = $4;"
        result, _ := db.Exec(sql_statement, a.DeviecModel, a.MemorySize, now, a.AccountId)

        row, err := result.RowsAffected()

        if row == 0 || err != nil {
            log.Panic().Stack().Err(err).Msg("Insert")
        }
    }
}
반응형

if val, ok := dict["key"]; ok {

}

'프로그래밍' 카테고리의 다른 글

Perforce Install in Ubuntu  (0) 2022.10.20
트랜잭션 문제  (0) 2022.10.18
게임 전투 데이터 AI 치터 판별 팁  (0) 2022.10.17
Detect anomalies in product sales with ML.NET  (0) 2022.10.14
jetbrains fleet  (0) 2022.10.13

+ Recent posts