Skip to content

Commit

Permalink
Merge pull request #19 from yunkon-kim/yunkon-kim-240214-1
Browse files Browse the repository at this point in the history
Add Dockerfile
  • Loading branch information
yunkon-kim authored Feb 14, 2024
2 parents 6618f5f + 99cad0a commit 74e0f29
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.github/
docs/

# Example files for tofu and infrastructure configurations (e.g. .tf files)
examples/

# Terrafrom files
*.tfstate
*.tfstate.backup
*.tfvars
.terraform/
.terraform.lock.hcl

# Secret files
*credential*

# Binaries
pkg/poc-mc-net-tf
pkg/poc-mc-net-tf-arm
cmd/poc-mc-net-tf/poc-mc-net-tf

# Log files
log/
logs/
*.log

# Files for tofu and infrastructure configurations
!.tofu/
.tofu/*
!.tofu/secrets
.tofu/secrets/*
!.tofu/secrets/.keep
!.tofu/template-tfs
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ go.work
*credential*
project-gcp.txt

aws

# Binaries
pkg/poc-mc-net-tf
pkg/poc-mc-net-tf-arm
cmd/poc-mc-net-tf/poc-mc-net-tf

# Log files
log/
logs/
*.log

# Files for tofu and infrastructure configurations
Expand Down
74 changes: 74 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
##############################################################
## Stage 1 - Go Build
##############################################################

# Using a specific version of golang based on alpine for building the application
FROM golang:1.21.4-alpine AS builder

# Installing necessary packages
# sqlite-libs and sqlite-dev for SQLite support
# build-base for common build requirements
RUN apk add --no-cache sqlite-libs sqlite-dev build-base

# Copying only necessary files for the build
COPY . /go/src/github.com/cloud-barista/poc-mc-net-tf
WORKDIR /go/src/github.com/cloud-barista/poc-mc-net-tf
# COPY go.mod go.sum go.work go.work.sum ./
RUN go mod download
# COPY .tofu ./.tofu
# COPY cmd ./cmd
# COPY conf ./conf
# COPY pkg ./pkg

# Building the Go application with specific flags
# Note - "make prod" executes the command,
# CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o poc-mc-net-tf"
RUN make prod

#############################################################
## Stage 2 - Application Setup
##############################################################

# Using the latest Ubuntu image for the production stage
FROM ubuntu:latest as prod

# Setting the working directory for the application
WORKDIR /app

# Copying necessary files from the builder stage to the production stage
# Assets, scripts, and configuration files are copied excluding credentials.conf
# which should be specified in .dockerignore
COPY --from=builder /go/src/github.com/cloud-barista/poc-mc-net-tf/.tofu/ /app/.tofu/
COPY --from=builder /go/src/github.com/cloud-barista/poc-mc-net-tf/conf/ /app/conf/
COPY --from=builder /go/src/github.com/cloud-barista/poc-mc-net-tf/scripts/ /app/scripts/
COPY --from=builder /go/src/github.com/cloud-barista/poc-mc-net-tf/cmd/poc-mc-net-tf/poc-mc-net-tf /app/

RUN ./scripts/install-tofu.sh

# Setting various environment variables required by the application
ENV POCMCNETTF_ROOT=/app \
LOGFILE_PATH=poc-mc-net-tf.log \
LOGFILE_MAXSIZE=10 \
LOGFILE_MAXBACKUPS=3 \
LOGFILE_MAXAGE=30 \
LOGFILE_COMPRESS=false \
LOGLEVEL=debug \
LOGWRITER=both \
NODE_ENV=development \
DB_URL=localhost:3306 \
DB_DATABASE=poc_mc_net_tf \
DB_USER=poc_mc_net_tf \
DB_PASSWORD=poc_mc_net_tf \
API_ALLOW_ORIGINS=* \
API_AUTH_ENABLED=true \
API_USERNAME=default \
API_PASSWORD=default \
AUTOCONTROL_DURATION_MS=10000 \
SELF_ENDPOINT=localhost:8888 \
API_DOC_PATH=/app/pkg/api/rest/docs/swagger.json

# Setting the entrypoint for the application
ENTRYPOINT [ "/app/poc-mc-net-tf" ]

# Exposing the port that the application will run on
EXPOSE 8888
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions scripts/install-tofu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Ensure that your system is up to date
apt update -y

# Ensure that you have installed the dependencies, such as `gnupg`, `software-properties-common`, `curl`, and unzip packages.
apt install -y curl

# Download the installer script:
curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh
# Alternatively: wget --secure-protocol=TLSv1_2 --https-only https://get.opentofu.org/install-opentofu.sh -O install-opentofu.sh

# Give it execution permissions:
chmod +x install-opentofu.sh

# Please inspect the downloaded script

# Run the installer:
./install-opentofu.sh --install-method deb

# Remove the installer:
rm install-opentofu.sh

0 comments on commit 74e0f29

Please sign in to comment.