Skip to content

Commit

Permalink
Add Dockerfile and Tofu installation script
Browse files Browse the repository at this point in the history
* Add .dockerignore
* Add Dockefile
* Add Tofu installation
  • Loading branch information
yunkon-kim committed Feb 14, 2024
1 parent 9739aaf commit 99cad0a
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 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
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
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 99cad0a

Please sign in to comment.