Skip to content
New issue

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

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

Already on GitHub? # to your account

Build Go app in Dockerfile for multi-arch deployments #38

Open
wants to merge 1 commit into
base: master
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
24 changes: 17 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.21
FROM golang:1.22.0 AS builder

WORKDIR /app

RUN \
mkdir -p /licenses && \
curl -s -q https://raw.githubusercontent.com/harshavardhana/s3www/master/CREDITS -o /licenses/CREDITS && \
curl -s -q https://raw.githubusercontent.com/harshavardhana/s3www/master/LICENSE -o /licenses/LICENSE
mkdir -p /app/licenses && \
curl -s -q https://raw.githubusercontent.com/harshavardhana/s3www/master/CREDITS -o /app/licenses/CREDITS && \
curl -s -q https://raw.githubusercontent.com/harshavardhana/s3www/master/LICENSE -o /app/licenses/LICENSE

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o s3www .

FROM scratch

EXPOSE 8080

# Copy CA certificates to prevent x509: certificate signed by unknown authority errors
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=0 /licenses /licenses
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

COPY --from=builder /app/licenses /licenses

COPY s3www /s3www
COPY --from=builder /app/s3www /s3www

ENTRYPOINT ["/s3www"]