Skip to content

Commit

Permalink
Run container as regular user. Build automations improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
automixer committed Feb 12, 2024
1 parent dc958fb commit 86e8c1f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
1 change: 0 additions & 1 deletion .github/workflows/devel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: "${{ github.repository }}:devel"
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ on:

jobs:
docker_image:
env:
Mode: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -42,11 +40,12 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
MODE=docker_release
gh_release:
runs-on: ubuntu-latest
Expand Down
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ FROM golang:1.22.0-bookworm as builder

WORKDIR /app
COPY . /app
ARG MODE=devel

RUN make clean docker
RUN make clean $MODE

FROM ubuntu:24.04

COPY --from=builder /app/build/* /usr/local/bin
COPY --from=builder /app/build/gtexporter /usr/local/bin

RUN groupadd -r gtexporter && \
useradd -r -g gtexporter gtexporter

USER gtexporter

ENTRYPOINT ["gtexporter"]
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GOARCH := $(shell go env GOARCH)
BIN_NAME := $(BUILD_DIR)/$(APP_NAME)
COMMIT_ID := $(shell git rev-parse --short HEAD)
LDFLAGS := '-X main.appName=$(APP_NAME) -X main.appVersion=dev-$(COMMIT_ID) -X main.buildDate=$(BUILD_DATE)'
.DEFAULT_GOAL := build
.DEFAULT_GOAL := devel

install_ygot_gen:
go install github.com/openconfig/ygot/generator@$(YGOT_GEN_VER)
Expand Down Expand Up @@ -38,7 +38,7 @@ clean:
rm -rf $(BUILD_DIR)
.PHONY: clean

build: prepare vet
devel: prepare vet
go build -ldflags $(LDFLAGS) -o $(BIN_NAME) $(SRC_PATH)*.go
.PHONY: build

Expand All @@ -49,11 +49,9 @@ release: prepare vet
go build -ldflags $(LDFLAGS) -o $(BIN_NAME)-$(GOOS)-$(GOARCH) $(SRC_PATH)*.go
.PHONY: release

docker: prepare vet
ifeq ($(Mode),Release)
docker_release: prepare vet
$(eval LDFLAGS := '-X main.appName=$(APP_NAME) \
-X main.appVersion=$(shell git describe --abbrev --tags HEAD)-$(COMMIT_ID) \
-X main.buildDate=$(BUILD_DATE)')
endif
go build -ldflags $(LDFLAGS) -o $(BIN_NAME) $(SRC_PATH)*.go
.PHONY: docker
.PHONY: docker_release

0 comments on commit 86e8c1f

Please sign in to comment.