Skip to content

Commit

Permalink
Merge pull request #122 from kpirnie/main
Browse files Browse the repository at this point in the history
Fix Dockerfile for Local Go Test with Redis
  • Loading branch information
sonroyaalmerol committed Aug 25, 2024
2 parents 7208da8 + 76a8325 commit db44a2f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 58 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/developer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- uses: shogo82148/actions-setup-redis@v1
with:
redis-version: "latest"

- name: Docker - Login
uses: docker/login-action@v3
with:
Expand All @@ -25,10 +21,6 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:master
network=host

- name: Docker - Metadata
id: meta
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- uses: shogo82148/actions-setup-redis@v1
with:
redis-version: "latest"

- name: Login to GitHub Container Registry
if: github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'push-to-ghcr')
uses: docker/login-action@v3
Expand All @@ -29,10 +25,6 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:master
network=host

- name: Docker - Metadata
id: meta
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- uses: shogo82148/actions-setup-redis@v1
with:
redis-version: "latest"

- name: Docker - Login
uses: docker/login-action@v3
with:
Expand All @@ -28,10 +24,6 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:master
network=host

- name: Docker - Metadata
id: meta
Expand Down
76 changes: 42 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
# Start from the official Golang image
FROM golang:alpine AS build

# Set the Current Working Directory inside the container
WORKDIR /app

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download

# Copy the source code from the current directory to the Working Directory inside the container
COPY . .

RUN go test ./... \
&& go build -ldflags='-s -w' -o main .

# End from the latest alpine image
# hadolint ignore=DL3007
FROM alpine:latest

# add bash and timezone data
# hadolint ignore=DL3018
RUN apk --no-cache add tzdata

# set the current workdir
WORKDIR /app

# copy in our compiled GO app
COPY --from=build /app/main /app/

# the containers entrypoint
ENTRYPOINT [ "/app/main" ]
# Start from the official Golang image
FROM golang:alpine AS build

# install redis
# hadolint ignore=DL3018
RUN apk --no-cache add redis && \
sed -i "s/bind .*/bind 127.0.0.1/g" /etc/redis.conf

# Set the Current Working Directory inside the container
WORKDIR /app

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download

# Copy the source code from the current directory to the Working Directory inside the container
COPY . .

# fire up redis server and test and build the app.
RUN \
redis-server --daemonize yes && \
go test ./... \
&& go build -ldflags='-s -w' -o main .

# End from the latest alpine image
# hadolint ignore=DL3007
FROM alpine:latest

# add bash and timezone data
# hadolint ignore=DL3018
RUN apk --no-cache add tzdata

# set the current workdir
WORKDIR /app

# copy in our compiled GO app
COPY --from=build /app/main /app/

# the containers entrypoint
ENTRYPOINT [ "/app/main" ]

0 comments on commit db44a2f

Please sign in to comment.