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 Makefile and refactor Dockerfile #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
oec

# Test binary, build with `go test -c`
*.test
Expand Down
39 changes: 24 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
FROM golang:1.14 as builder
ADD . $GOPATH/src/github.com/opsgenie/oec
FROM golang:1.23 as builder

COPY . $GOPATH/src/github.com/opsgenie/oec

WORKDIR $GOPATH/src/github.com/opsgenie/oec/main
RUN export GIT_COMMIT=$(git rev-list -1 HEAD) && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo \
-ldflags "-X main.OECCommitVersion=$GIT_COMMIT -X main.OECVersion=1.0.1" -o nocgo -o /oec .
FROM python:alpine3.16 as base
RUN pip install requests
RUN export GIT_COMMIT=$(git rev-list -1 HEAD)

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo \
-ldflags "-X main.OECCommitVersion=$GIT_COMMIT -X main.OECVersion=1.0.1" -o nocgo -o /oec .


FROM python:alpine3.20 as base
RUN --mount=type=bind,source=requirements.txt,target=requirements.txt pip install -r requirements.txt

RUN apk update && \
apk add --virtual --no-cache git ca-certificates && \
update-ca-certificates

RUN addgroup -S opsgenie && \
adduser -S opsgenie -G opsgenie && \
apk update && \
apk add --no-cache git ca-certificates && \
update-ca-certificates
COPY --from=builder /oec /opt/oec
RUN mkdir -p /var/log/opsgenie && \
chown -R opsgenie:opsgenie /var/log/opsgenie && \
chown -R opsgenie:opsgenie /opt/oec
mkdir -p /var/log/opsgenie && \
chown -R opsgenie:opsgenie /var/log/opsgenie

COPY --from=builder --chown=opsgenie:opsgenie /oec /opt/oec

USER opsgenie
ENTRYPOINT ["/opt/oec"]

ENTRYPOINT ["/opt/oec"]
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.PHONY: all
all: test build

.PHONY: build
build: fmt
go build -a -o oec main/main.go

.PHONY: test
test:
go test ./...

.PHONY: fmt
fmt:
go fmt ./...

.PHONY: update
update:
go get -u ./...
go mod tidy
go mod vendor

.PHONY: docker
docker:
docker build -t oec:latest .
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests