Skip to content

Commit

Permalink
Implement docker multi stage build and use common Go image (#265)
Browse files Browse the repository at this point in the history
* implement multi-stage build

* update github actions

* update github actions
  • Loading branch information
chimanjain authored Feb 21, 2024
1 parent 8df0599 commit 0fa115f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
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/

.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) .
$(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

0 comments on commit 0fa115f

Please sign in to comment.