Skip to content

Commit

Permalink
added cross compilation for docker image, removed whitespaces from en…
Browse files Browse the repository at this point in the history
…v template
  • Loading branch information
smegg99 committed Nov 24, 2024
1 parent b828c6d commit e4c3842
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
14 changes: 7 additions & 7 deletions app/.env.template
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
DB_FILE_PATH = "./db"
DB_FILE_PATH="./db"

GIN_MODE = "release"
DIST_PATH = "./dist"
GIN_MODE="release"
DIST_PATH="./dist"

CONFIG_PATH = "./"
CONFIG_TYPE = "json"
CONFIG_PURPOSE = "prod"
CONFIG_PATH="./"
CONFIG_TYPE="json"
CONFIG_PURPOSE="prod"

OPENWEATHER_API_KEY = ""
OPENWEATHER_API_KEY=""
25 changes: 19 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ OS := linux
DOCKER_IMAGE_NAME := $(shell echo $(PROJECT_NAME) | tr '[:upper:]' '[:lower:]'):$(VERSION)
DOCKER_COMPOSE := docker-compose
DOCKER_COMPOSE_FILE := $(PROJECT_ROOT)/docker-compose.yml
DOCKER_PACKAGE_NAME := goptivum

DOCKERHUB_USERNAME ?= smeggmann99

Expand Down Expand Up @@ -52,13 +53,13 @@ build-web-install: | $(CURRENT_BUILD_DIR)
package: all
@echo "Packaging tarballs for version $(VERSION)..."
@for arch in $(ARCHS); do \
BUILD_ARCHIVE=$(BUILD_DIR)/$(PROJECT_NAME)-$(VERSION)-$(OS)-static-$$arch.tar.gz; \
BUILD_ARCHIVE=$(BUILD_DIR)/$(shell echo $(PROJECT_NAME) | tr '[:upper:]' '[:lower:]')-$(VERSION)-$(OS)-static-$$arch.tar.gz; \
echo "Building for $$arch..."; \
TEMP_DIR=$(BUILD_DIR)/temp_$$arch; \
mkdir -p $$TEMP_DIR/Goptivum; \
GOOS=$(OS) GOARCH=$$arch CGO_ENABLED=0 go build -a -installsuffix cgo -o $$TEMP_DIR/Goptivum/$(BINARY_NAME) $(BACKEND_SOURCE_DIR); \
cp -r $(CURRENT_BUILD_DIR)/config.json $$TEMP_DIR/Goptivum/config.json; \
cp -r $(CURRENT_BUILD_DIR)/.env $$TEMP_DIR/Goptivum/.env; \
sed 's/^OPENWEATHER_API_KEY=.*/OPENWEATHER_API_KEY=""/' $(CURRENT_BUILD_DIR)/.env > $$TEMP_DIR/Goptivum/.env; \
cp -r $(DIST_DIR) $$TEMP_DIR/Goptivum/dist; \
echo "Creating archive $$BUILD_ARCHIVE..."; \
tar -czvf $$BUILD_ARCHIVE -C $$TEMP_DIR Goptivum; \
Expand Down Expand Up @@ -89,11 +90,23 @@ docker-clean:
.PHONY: docker-publish
docker-publish: docker-build
@echo "Tagging Docker image for publishing..."
@docker tag goptivum:$(VERSION) $(DOCKERHUB_USERNAME)/goptivum:$(VERSION)
@docker tag goptivum:$(VERSION) $(DOCKERHUB_USERNAME)/goptivum:latest
@docker tag $(DOCKERHUB_USERNAME)/$(DOCKER_PACKAGE_NAME):$(VERSION) $(DOCKERHUB_USERNAME)/$(DOCKER_PACKAGE_NAME):$(VERSION)
@docker tag $(DOCKERHUB_USERNAME)/$(DOCKER_PACKAGE_NAME):$(VERSION) $(DOCKERHUB_USERNAME)/$(DOCKER_PACKAGE_NAME):latest
@echo "Pushing Docker image to Docker Hub..."
@docker push $(DOCKERHUB_USERNAME)/goptivum:$(VERSION)
@docker push $(DOCKERHUB_USERNAME)/goptivum:latest
@docker push $(DOCKERHUB_USERNAME)/$(DOCKER_PACKAGE_NAME):$(VERSION)
@docker push $(DOCKERHUB_USERNAME)/$(DOCKER_PACKAGE_NAME):latest

.PHONY: docker-build-publish
docker-build-publish:
@echo "Building and publishing multi-architecture Docker images..."
@docker buildx build \
--platform linux/amd64,linux/arm64,linux/arm \
--build-arg VERSION=$(VERSION) \
--tag $(DOCKERHUB_USERNAME)/$(DOCKER_PACKAGE_NAME):$(VERSION) \
--tag $(DOCKERHUB_USERNAME)/$(DOCKER_PACKAGE_NAME):latest \
--push \
-f $(PROJECT_ROOT)/dockerfile $(PROJECT_ROOT)
@echo "Docker images built and published for architectures: amd64, arm64, arm."

.PHONY: clean
clean:
Expand Down

0 comments on commit e4c3842

Please sign in to comment.