Skip to content

Commit

Permalink
Update pool price docker file and ioutil->io in main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinmartian committed Oct 29, 2024
1 parent c6cf967 commit 3c57514
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions Dockerfile.price
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Use the official Go image as the base image
FROM golang:alpine AS build-stage

# Install necessary packages (OpenSSL and ca-certificates)
RUN apk --no-cache add openssl ca-certificates

# Fetch the server certificate and store it
RUN echo "Fetching server certificate..." \
&& openssl s_client -showcerts -connect www.aeso.ca:443 </dev/null 2>/dev/null | \
awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/{print}' > /usr/local/share/ca-certificates/server.crt \
&& update-ca-certificates

# Set the working directory inside the container
WORKDIR /app

Expand All @@ -10,16 +19,23 @@ COPY poolprice/ .
# Build the Go application
RUN go build -o main .

# Final stage
# Final stage (minimal image with only the Go binary and certificates)
FROM golang:alpine

WORKDIR /app

# Copy only the built binary from the build stage
COPY --from=build-stage /app/main .

# Copy the certificates from the build stage to the final stage
COPY --from=build-stage /etc/ssl/certs /etc/ssl/certs
COPY --from=build-stage /usr/local/share/ca-certificates /usr/local/share/ca-certificates

# Ensure all certificates are up to date in the final stage
RUN update-ca-certificates

# Expose the port that the application will run on
EXPOSE 8080

# Command to run the executable
CMD ["./main"]
CMD ["./main"]
4 changes: 2 additions & 2 deletions poolprice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"time"
Expand Down Expand Up @@ -43,7 +43,7 @@ func getCurrentPoolPrice() {
defer resp.Body.Close()

if resp.StatusCode == http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal("Error reading response body:", err)
}
Expand Down

0 comments on commit 3c57514

Please sign in to comment.