Skip to content

Commit

Permalink
Merge pull request #296 from gatewayd-io/add-dockerfile
Browse files Browse the repository at this point in the history
Add dockerfile
  • Loading branch information
mostafa authored Jul 30, 2023
2 parents 81ae695 + 5d15f29 commit 8281b5c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ jobs:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
generate_release_notes: true
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
ghcr.io/gatewayd-io/gatewayd:${{ github.ref_name }}
ghcr.io/gatewayd-io/gatewayd:latest
platforms: linux/amd64
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# syntax=docker/dockerfile:1

# Use the official golang image to build the binary.
FROM golang:1.20-alpine3.18 as builder

ARG TARGETOS
ARG TARGETARCH
ARG TARGETPLATFORM

# IF YOU SEE THIS MESSAGE, IT MEANS THAT THE PLATFORM YOU CHOSE IS NOT SUPPORTED
RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
echo "Target platform ${TARGETPLATFORM} is supported"; \
else \
echo "Target platform ${TARGETPLATFORM} is not supported"; \
exit 1; \
fi

WORKDIR /gatewayd
COPY . /gatewayd

RUN apk --no-cache add git make
RUN mkdir -p dist
RUN make build-${TARGETOS}-${TARGETARCH}

# Use alpine to create a minimal image to run the gatewayd binary.
FROM alpine:3.18 as runner

ARG TARGETOS
ARG TARGETARCH

COPY --from=builder /gatewayd/dist/${TARGETOS}-${TARGETARCH}/gatewayd /usr/bin/
COPY --from=builder /gatewayd/gatewayd.yaml /etc/gatewayd.yaml
COPY --from=builder /gatewayd/gatewayd_plugins.yaml /etc/gatewayd_plugins.yaml

ENTRYPOINT ["/usr/bin/gatewayd"]
22 changes: 14 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,59 @@ tidy:
build-dev:
@go mod tidy && CGO_ENABLED=0 go build -tags embed_swagger -trimpath -ldflags "-s -w -X ${CONFIG_PACKAGE}.Version=${VERSION} -X ${CMD_PACKAGE}.UsageReportURL=localhost:59091"

build-release: tidy
create-build-dir:
@mkdir -p dist

build-windows-amd64: tidy
@echo "Building gatewayd ${VERSION} for windows-amd64"
@mkdir -p dist/windows-amd64
@cp README.md LICENSE gatewayd.yaml gatewayd_plugins.yaml dist/windows-amd64/
@GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -tags embed_swagger,windows -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/windows-amd64/gatewayd.exe
@zip -r dist/gatewayd-windows-amd64-${VERSION}.zip -j ./dist/windows-amd64/
@sha256sum dist/gatewayd-windows-amd64-${VERSION}.zip | sed 's/dist\///g' >> dist/checksums.txt

build-windows-arm64: tidy
@echo "Building gatewayd ${VERSION} for windows-arm64"
@mkdir -p dist/windows-arm64
@cp README.md LICENSE gatewayd.yaml gatewayd_plugins.yaml dist/windows-arm64/
@GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build -tags embed_swagger,windows -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/windows-arm64/gatewayd.exe
@zip -r dist/gatewayd-windows-arm64-${VERSION}.zip -j ./dist/windows-arm64/
@sha256sum dist/gatewayd-windows-arm64-${VERSION}.zip | sed 's/dist\///g' >> dist/checksums.txt

build-linux-amd64: tidy
@echo "Building gatewayd ${VERSION} for linux-amd64"
@mkdir -p dist/linux-amd64
@cp README.md LICENSE gatewayd.yaml gatewayd_plugins.yaml dist/linux-amd64/
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -tags embed_swagger -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/linux-amd64/gatewayd
@tar czf dist/gatewayd-linux-amd64-${VERSION}.tar.gz -C ./dist/linux-amd64/ ${FILES}
@sha256sum dist/gatewayd-linux-amd64-${VERSION}.tar.gz | sed 's/dist\///g' >> dist/checksums.txt

build-linux-arm64: tidy
@echo "Building gatewayd ${VERSION} for linux-arm64"
@mkdir -p dist/linux-arm64
@cp README.md LICENSE gatewayd.yaml gatewayd_plugins.yaml dist/linux-arm64/
@GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -tags embed_swagger -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/linux-arm64/gatewayd
@tar czf dist/gatewayd-linux-arm64-${VERSION}.tar.gz -C ./dist/linux-arm64/ ${FILES}
@sha256sum dist/gatewayd-linux-arm64-${VERSION}.tar.gz | sed 's/dist\///g' >> dist/checksums.txt

build-darwin-amd64: tidy
@echo "Building gatewayd ${VERSION} for darwin-amd64"
@mkdir -p dist/darwin-amd64
@cp README.md LICENSE gatewayd.yaml gatewayd_plugins.yaml dist/darwin-amd64/
@GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -tags embed_swagger -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/darwin-amd64/gatewayd
@tar czf dist/gatewayd-darwin-amd64-${VERSION}.tar.gz -C ./dist/darwin-amd64/ ${FILES}
@sha256sum dist/gatewayd-darwin-amd64-${VERSION}.tar.gz | sed 's/dist\///g' >> dist/checksums.txt

build-darwin-arm64: tidy
@echo "Building gatewayd ${VERSION} for darwin-arm64"
@mkdir -p dist/darwin-arm64
@cp README.md LICENSE gatewayd.yaml gatewayd_plugins.yaml dist/darwin-arm64/
@GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -tags embed_swagger -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/darwin-arm64/gatewayd
@tar czf dist/gatewayd-darwin-arm64-${VERSION}.tar.gz -C ./dist/darwin-arm64/ ${FILES}

@echo "Generating checksums"
@sha256sum dist/gatewayd-linux-amd64-${VERSION}.tar.gz | sed 's/dist\///g' > dist/checksums.txt
@sha256sum dist/gatewayd-linux-arm64-${VERSION}.tar.gz | sed 's/dist\///g' >> dist/checksums.txt
@sha256sum dist/gatewayd-windows-amd64-${VERSION}.zip | sed 's/dist\///g' >> dist/checksums.txt
@sha256sum dist/gatewayd-windows-arm64-${VERSION}.zip | sed 's/dist\///g' >> dist/checksums.txt
@sha256sum dist/gatewayd-darwin-amd64-${VERSION}.tar.gz | sed 's/dist\///g' >> dist/checksums.txt
@sha256sum dist/gatewayd-darwin-arm64-${VERSION}.tar.gz | sed 's/dist\///g' >> dist/checksums.txt

build-release: create-build-dir build-windows-amd64 build-windows-arm64 build-linux-amd64 build-linux-arm64 build-darwin-amd64 build-darwin-arm64

build-linux-packages:
@echo "Building gatewayd ${VERSION} for linux-amd64"
@VERSION=${VERSION} GOARCH=amd64 envsubst < nfpm.yaml > nfpm-current.yaml
Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3.8"
services:
postgres:
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
gatewayd:
image: gatewayd:latest
command: ["run"]
environment:
# For more information about the environment variables, see:
# https://gatewayd.io/docs/using-gatewayd/configuration#environment-variables
- GATEWAYD_CLIENTS_DEFAULT_ADDRESS=postgres:5432
# - GATEWAYD_LOGGERS_DEFAULT_LEVEL=debug
ports:
- "15432:15432"
links:
- postgres
depends_on:
postgres:
condition: service_healthy

0 comments on commit 8281b5c

Please sign in to comment.