Skip to content
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

Add Dockerfile #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
43 changes: 23 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
# Start from the latest golang base image
FROM golang:alpine
# Build Stage
FROM golang:alpine AS builder

# Add Maintainer Info
LABEL org.opencontainers.image.source=https://github.com/chefgs/linktoqr
LABEL description="This container image can be used to generate QR from the given URL or Text."
LABEL org.opencontainers.image.licenses=MIT
# Set environment variables to make builds more efficient
ENV CGO_ENABLED=0 GOOS=linux GO111MODULE=on

# Set necessary environment variables needed for our image
ENV CGO_ENABLED=0 \
GOOS=linux \
GOOS=darwin \
GO111MODULE=on


# Move to working directory /linktoqr
# Set working directory
WORKDIR /linktoqr

# Copy and download dependency using go mod
COPY go.mod .
# Copy go.mod and go.sum to download dependencies
COPY go.mod ./
RUN go mod tidy

# Copy the code into the container
# Copy the source code into the container
COPY . .

# Export necessary port
# Build the binary using main.go from the specified location
RUN go build -o linktoqr ./main/main.go

# Final Stage
FROM alpine:latest

# Set working directory
WORKDIR /linktoqr

# Copy only the compiled binary from the builder stage
COPY --from=builder /linktoqr/linktoqr .

# Expose the port for the application
EXPOSE 1718

# Command to run the executable
CMD ["go", "run", "./..."]
# Command to run the application
CMD ["./linktoqr"]