Skip to content

Containarize application #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ jobs:
git status --porcelain
exit 1
fi

container_build:
name: "build container image"
runs-on: ubuntu-latest

steps:
- name: "Fetch source code"
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: "Build container image"
run: |
docker build --output type=docker -t terraform-config-inspect:ci-${{ github.run_id }}-${{ github.run_number }} -f build/Dockerfile .
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ $ terraform-config-inspect --json path/to/module
}
```

## Containarized

One can build a container version of this application with the following
oneliner:
`docker build -t terraform-config-inspect:latest -f build/Dockerfile .`

Feel free to use our development stage to debug or when contributing to this
project by including the `--target dev` in the container build phase.

Example:
- How to use the generated image if you current context is the module you want
to analyze:
`docker run -it -v $(pwd):/$(pwd) -w $(pwd) terraform-config-inspect:latest`

## Contributing

This library and tool are intentionally focused on only extracting simple
Expand Down
65 changes: 65 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
ARG BUILD_GO_IMAGE=golang:1.18-alpine
ARG LIVE_GO_IMAGE=scratch

###
### Setup
###

### Setup Build
FROM ${BUILD_GO_IMAGE} AS setup-build

ARG GOARCH
ARG GOOS=linux

ENV GOARCH=${GOARCH}
ENV GOBIN=${GOPATH}/bin
ENV GOOS=${GOOS}

WORKDIR /usr/local/src

# Ease the debugging and development build by adding the go
# installed binaries to the PATH
ENV PATH=${PATH}:${GOBIN}

# Copy go.mod and go.sum files seperatly to allow caching
# of dependencies
COPY go.* ./
# Download dependencies
RUN go mod download

COPY . .

### Setup Live Image
FROM ${LIVE_GO_IMAGE} AS setup-live

COPY --from=setup-build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

###
### Build
###
FROM setup-build AS build

# Build the application binary
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${GOBIN}/terraform-config-inspect .

###
### Final Images
###

### Dev
# This stage is used for development and debugging purposes,
# but it can also be used for CI-related tasks, and others.
FROM setup-build AS dev

# Install delve debugger (the delve version shouldn't be a concern 🤷‍♂️)
RUN go install github.com/go-delve/delve/cmd/dlv@latest

# Explicitly not overriding the entrypoint of the source image
# ENTRYPOINT [ "" ]

### Live
FROM setup-live AS live

COPY --from=build /go/bin/terraform-config-inspect /

ENTRYPOINT ["/terraform-config-inspect"]