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

Implement docker multi stage build and use common Go image #265

Merged
merged 3 commits into from
Feb 21, 2024
Merged
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
8 changes: 7 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
# Rodrigo Bassil (rodrigobassil)
# Anand Raja Kesavamoorhty (anandrajak1)
# Abhilash Muralidhara (abhi16394)
# Chiman Jain (chimanjain)
# Harish H (HarishH-DELL)
# Nitesh Rewatkar (nitesh3108)
# Rajendra Indukuri (rajendraindukuri)
# Shefali Malhotra (shefali-malhotra)
# Spandita Panigrahi (panigs7)

# for all files:
* @gallacher @tdawe @alikdell @atye @hoppea2 @coulof @shaynafinocchiaro @sharmilarama @EvgenyUglov @bjiang27 @xuluna @PeresKereotubo @EmilyKatdell @KerryKovacevic @MaksimDell @jooseppi-luna @Sahiba-Gupta @jackieung-dell @rodrigobassil @anandrajak1 @abhi16394
* @gallacher @tdawe @alikdell @atye @hoppea2 @coulof @shaynafinocchiaro @sharmilarama @EvgenyUglov @bjiang27 @xuluna @PeresKereotubo @EmilyKatdell @KerryKovacevic @MaksimDell @jooseppi-luna @Sahiba-Gupta @jackieung-dell @rodrigobassil @anandrajak1 @abhi16394 @chimanjain @shefali-malhotra @panigs7 @nitesh3108 @rajendraindukuri @HarishH-DELL
12 changes: 6 additions & 6 deletions .github/workflows/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run the formatter, linter, and vetter
uses: dell/common-github-actions/go-code-formatter-linter-vetter@main
with:
Expand All @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run the forbidden words scan
uses: dell/common-github-actions/code-sanitizer@main
with:
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run Go Security
uses: securego/gosec@master
with:
Expand All @@ -70,7 +70,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run malware scan
uses: dell/common-github-actions/malware-scanner@main
with:
Expand All @@ -81,12 +81,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.21+
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ^1.21
id: go
- name: Checkout the code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Mockgen
run: go get github.com/golang/mock/[email protected]
- name: Get dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ jobs:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
cache: false
- name: Checkout the code
uses: actions/checkout@v3.2.0
uses: actions/checkout@v4
- name: Vendor packages
run: |
go mod vendor
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: latest
skip-cache: true
14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ARG GOIMAGE
ARG BASEIMAGE

# Stage to build the module
FROM $GOIMAGE as builder

ARG APP

WORKDIR /workspace
COPY . .
RUN go mod download

RUN CGO_ENABLED=0 go build -o $APP ./cmd/$APP

FROM $BASEIMAGE as final
LABEL vendor="Dell Inc." \
name="csm-authorization" \
Expand All @@ -23,6 +35,6 @@ LABEL vendor="Dell Inc." \
ARG APP

WORKDIR /app
COPY $APP /app/command
COPY --from=builder /workspace/$APP /app/command

ENTRYPOINT [ "/app/command" ]
16 changes: 5 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ K3S_SELINUX_VERSION ?= 0.4-1
.PHONY: build
build:
-mkdir -p ./bin
cp Dockerfile ./bin/Dockerfile
CGO_ENABLED=0 go build -o ./bin ./cmd/proxy-server/
CGO_ENABLED=0 go build -o ./bin ./cmd/karavictl/
CGO_ENABLED=0 go build -o ./bin ./cmd/sidecar-proxy/
CGO_ENABLED=0 go build -o ./bin ./cmd/tenant-service/
CGO_ENABLED=0 go build -o ./bin ./cmd/role-service/
CGO_ENABLED=0 go build -o ./bin ./cmd/storage-service/
shefali-malhotra marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: build-installer
build-installer:
Expand Down Expand Up @@ -86,11 +80,11 @@ redeploy: build builder
.PHONY: builder
builder: build download-csm-common
$(eval include csm-common.mk)
$(BUILDER) build -t localhost/proxy-server:$(BUILDER_TAG) --build-arg APP=proxy-server --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) ./bin/.
$(BUILDER) build -t localhost/sidecar-proxy:$(SIDECAR_TAG) --build-arg APP=sidecar-proxy --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) ./bin/.
$(BUILDER) build -t localhost/tenant-service:$(BUILDER_TAG) --build-arg APP=tenant-service --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) ./bin/.
$(BUILDER) build -t localhost/role-service:$(BUILDER_TAG) --build-arg APP=role-service --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) ./bin/.
$(BUILDER) build -t localhost/storage-service:$(BUILDER_TAG) --build-arg APP=storage-service --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) ./bin/.
$(BUILDER) build -t localhost/proxy-server:$(BUILDER_TAG) --build-arg APP=proxy-server --build-arg GOIMAGE=$(DEFAULT_GOIMAGE) --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) .
atye marked this conversation as resolved.
Show resolved Hide resolved
$(BUILDER) build -t localhost/sidecar-proxy:$(SIDECAR_TAG) --build-arg APP=sidecar-proxy --build-arg GOIMAGE=$(DEFAULT_GOIMAGE) --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) .
$(BUILDER) build -t localhost/tenant-service:$(BUILDER_TAG) --build-arg APP=tenant-service --build-arg GOIMAGE=$(DEFAULT_GOIMAGE) --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) .
$(BUILDER) build -t localhost/role-service:$(BUILDER_TAG) --build-arg APP=role-service --build-arg GOIMAGE=$(DEFAULT_GOIMAGE) --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) .
$(BUILDER) build -t localhost/storage-service:$(BUILDER_TAG) --build-arg APP=storage-service --build-arg GOIMAGE=$(DEFAULT_GOIMAGE) --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) .

.PHONY: protoc
protoc:
Expand Down
Loading