Skip to content

Commit

Permalink
Merge pull request #1096 from sundowndev/fix/dockerfile
Browse files Browse the repository at this point in the history
Fix Dockerfile
  • Loading branch information
sundowndev committed Jul 17, 2022
2 parents a9ed144 + 755359e commit 8315413
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 43 deletions.
10 changes: 6 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
bin/
Dockerfile
client/node_modules
.git
*Dockerfile*
*docker-compose*
node_modules
*.md
*.out
*.xml
support
40 changes: 10 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,23 @@ FROM node:15.11.0-alpine AS client_builder
WORKDIR /app

COPY ./client .

RUN yarn install --immutable && \
yarn build && \
yarn cache clean
RUN yarn install --immutable
RUN yarn build
RUN yarn cache clean

FROM golang:1.17.8-alpine AS go_builder

LABEL maintainer="Sundowndev" \
org.label-schema.name="phoneinfoga" \
org.label-schema.description="Advanced information gathering & OSINT tool for phone numbers." \
org.label-schema.url="https://github.com/sundowndev/phoneinfoga" \
org.label-schema.vcs-url="https://github.com/sundowndev/phoneinfoga" \
org.label-schema.vendor="Sundowndev" \
org.label-schema.schema-version="1.0"

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download
RUN apk add --update --no-cache git make bash
COPY . .

RUN apk add --no-cache git && \
go get -v -t -d ./...

COPY --from=client_builder /app/dist ./client/dist
RUN go get -v -t -d ./...
RUN make install-tools
RUN make build

RUN go generate ./... && \
go build -v -ldflags="-s -w \
-X 'github.com/sundowndev/phoneinfoga/v2/config.Version=$(git describe --abbrev=0 --tags)' \
-X 'github.com/sundowndev/phoneinfoga/v2/config.Commit=$(git rev-parse --short HEAD)'" -v -o phoneinfoga .

FROM alpine:3.15

WORKDIR /app

COPY --from=go_builder /app/phoneinfoga .

FROM alpine:3.16
COPY --from=go_builder /app/bin/phoneinfoga /app/phoneinfoga
EXPOSE 5000

ENTRYPOINT ["/app/phoneinfoga"]
CMD ["--help"]
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ GOGET=$(GOCMD) get
GOINSTALL=$(GOCMD) install
GOTOOL=$(GOCMD) tool
GOFMT=$(GOCMD) fmt
GIT_TAG=$(shell git describe --abbrev=0 --tags)
GIT_COMMIT=$(shell git rev-parse --short HEAD)

.PHONY: FORCE

Expand All @@ -20,7 +22,7 @@ all: fmt lint test build go.mod
.PHONY: build
build:
go generate ./...
go build -v -o bin/phoneinfoga .
go build -v -ldflags="-s -w -X 'github.com/sundowndev/phoneinfoga/v2/build.Version=${GIT_TAG}' -X 'github.com/sundowndev/phoneinfoga/v2/build.Commit=${GIT_COMMIT}'" -o ./bin/phoneinfoga .

.PHONY: test
test:
Expand Down
10 changes: 10 additions & 0 deletions build/build.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package build

import "fmt"

// Version is the corresponding release tag
var Version = "dev"

// Commit is the corresponding Git commit
var Commit = "dev"

func IsRelease() bool {
return String() != "dev-dev"
}

func String() string {
return fmt.Sprintf("%s-%s", Version, Commit)
}
9 changes: 9 additions & 0 deletions build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,14 @@ func TestBuild(t *testing.T) {
t.Run("version and commit default values", func(t *testing.T) {
assert.Equal(t, "dev", Version)
assert.Equal(t, "dev", Commit)
assert.Equal(t, false, IsRelease())
assert.Equal(t, "dev-dev", String())
})

t.Run("version and commit default values", func(t *testing.T) {
Version = "v2.4.4"
Commit = "0ba854f"
assert.Equal(t, true, IsRelease())
assert.Equal(t, "v2.4.4-0ba854f", String())
})
}
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Print current version of the tool",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("PhoneInfoga %s-%s\n", build.Version, build.Commit)
fmt.Printf("PhoneInfoga %s\n", build.String())
},
}
7 changes: 0 additions & 7 deletions support/scripts/format

This file was deleted.

0 comments on commit 8315413

Please sign in to comment.