started with makefile update

This commit is contained in:
Annika Hannig 2022-07-27 18:54:55 +02:00
parent 240a49065d
commit f1fa264043
5 changed files with 37 additions and 119 deletions

View File

@ -4,26 +4,23 @@
# #
# Build frontend first # Build frontend first
FROM node:11 AS frontend FROM node:latest AS ui
# Install dependencies # Install dependencies
WORKDIR /src/alice-lg/client WORKDIR /src/alice-lg/ui
ADD client/package.json . ADD ui/package.json .
ADD client/yarn.lock . ADD ui/yarn.lock .
RUN npm install -g gulp@4.0.0
RUN npm install -g gulp-cli
RUN yarn install RUN yarn install
# Add frontend # Add frontend
WORKDIR /src/alice-lg/client ADD ui/ .
ADD client .
# Build frontend # Build frontend
RUN DISABLE_LOGGING=1 NODE_ENV=production /usr/local/bin/gulp RUN yarn build
# Build the backend # Build the backend
FROM golang:1.17 AS backend FROM golang:1.18 AS backend
# Install dependencies # Install dependencies
WORKDIR /src/alice-lg WORKDIR /src/alice-lg
@ -34,7 +31,7 @@ RUN go mod download
ADD . . ADD . .
# Add client # Add client
COPY --from=frontend /src/alice-lg/client/build client/build COPY --from=ui /src/alice-lg/ui/build ui/build
WORKDIR /src/alice-lg/cmd/alice-lg WORKDIR /src/alice-lg/cmd/alice-lg
RUN make alpine RUN make alpine

110
Makefile
View File

@ -1,119 +1,39 @@
# #
# Build the Alice Looking Glass # Build the Alice Looking Glass locally
# -----------------------------
#
# #
PROG=alice-lg PROG=alice-lg
ARCH=amd64 ARCH=amd64
SYSTEM_INIT=systemd
# == END BUILD CONFIGURATION ==
VERSION=$(shell cat ./VERSION) VERSION=$(shell cat ./VERSION)
# Specify build server for remotely building the RPM
# you can do this when you invoke the makefile
# using:
# make remote_rpm BUILD_SERVER=build-rpm.example.com
BUILD_SERVER=''
DIST=DIST/
REMOTE_DIST=$(PROG)-$(DIST)
RPM=$(PROG)-$(VERSION)-1.x86_64.rpm
LOCAL_RPMS=RPMS
all: alice all: alice
client_dev: test: ui_test backend_test
$(MAKE) -C client/
client_prod: alice: ui backend
$(MAKE) -C client/ client_prod
backend_prod: client_prod
$(MAKE) -C cmd/alice-lg/ linux
backend:
$(MAKE) -C cmd/alice-lg/ linux
backend_tests:
go test ./pkg/...
test: backend_tests
alice: backend_tests backend_prod
cp cmd/alice-lg/alice-lg-* bin/ cp cmd/alice-lg/alice-lg-* bin/
ui:
$(MAKE) -C ui/
dist: clean alice ui_test:
$(MAKE) -C ui/ test
mkdir -p $(DIST)opt/alice-lg/alice-lg/bin backend:
mkdir -p $(DIST)etc/alice-lg $(MAKE) -C cmd/alice-lg/ static
# Adding post install script backend_test:
cp install/scripts/after_install $(DIST)/. go test ./pkg/...
ifeq ($(SYSTEM_INIT), systemd)
# Installing systemd services
mkdir -p $(DIST)usr/lib/systemd/system/
cp install/systemd/* $(DIST)usr/lib/systemd/system/.
else
# Installing upstart configuration
mkdir -p $(DIST)/etc/init/
cp install/upstart/* $(DIST)etc/init/.
endif
# Copy example configuration
cp etc/alice-lg/alice.example.conf $(DIST)/etc/alice-lg/alice.example.conf
# Copy application
cp bin/$(PROG)-linux-$(ARCH) DIST/opt/alice-lg/alice-lg/bin/.
rpm: dist
# Clear tmp failed build (if any)
mkdir -p $(LOCAL_RPMS)
# Create RPM from dist
fpm -s dir -t rpm -n $(PROG) -v $(VERSION) -C $(DIST) \
--architecture $(ARCH) \
--config-files /etc/alice-lg/alice.example.conf \
--after-install $(DIST)/after_install \
opt/ etc/
mv $(RPM) $(LOCAL_RPMS)
build_server:
ifeq ($(BUILD_SERVER), '')
$(error BUILD_SERVER not configured)
endif
remote_rpm: build_server dist
mkdir -p $(LOCAL_RPMS)
# Copy distribution to build server
ssh $(BUILD_SERVER) -- rm -rf $(REMOTE_DIST)
scp -r $(DIST) $(BUILD_SERVER):$(REMOTE_DIST)
ssh $(BUILD_SERVER) -- fpm -s dir -t rpm -n $(PROG) -v $(VERSION) -C $(REMOTE_DIST) \
--architecture $(ARCH) \
--config-files /etc/alice-lg/alice.example.conf \
--after-install $(REMOTE_DIST)/after_install \
opt/ etc/
# Get rpm from server
scp $(BUILD_SERVER):$(RPM) $(LOCAL_RPMS)/.
clean: clean:
rm -f bin/alice-lg-linux-amd64 rm -f bin/alice-lg-linux-amd64
rm -f bin/alice-lg-osx-amd64 rm -f bin/alice-lg-osx-amd64
rm -rf $(DIST) rm -rf $(DIST)
.PHONY: backend ui clean

View File

@ -3,14 +3,16 @@
DOCKER := docker DOCKER := docker
DOCKER_CONTAINER := alice-lg-build
DOCKER_IMAGE := golang:1.18
all: alice all: alice
cp cmd/alice-lg/alice-lg-* bin/ cp cmd/alice-lg/alice-lg-* bin/
client: ui:
$(MAKE) -C client/ -f Makefile.docker client_prod $(MAKE) -C ui/ -f Makefile.docker client_prod
alice: client alice: client
$(MAKE) -C cmd/alice-lg -f Makefile.docker $(MAKE) -C cmd/alice-lg -f Makefile.docker
.PHONY: client alice .PHONY: client alice

View File

@ -1 +1 @@
5.1.1 6.0.0

View File

@ -1,6 +1,5 @@
# #
# Alice LG Backend # Alice LG Backend Makefile
# ----------------
# #
PROG=alice-lg PROG=alice-lg
@ -28,31 +27,31 @@ all: deps $(TARGET)
@echo "Built $(VERSION) @ $(TARGET)" @echo "Built $(VERSION) @ $(TARGET)"
deps: deps:
GO111MODULE=on go get -v . go get -v .
osx-dev: osx-dev:
GO111MODULE=on go run $(FILES) go run $(FILES)
osx: osx:
GO111MODULE=on GOARCH=$(ARCH) GOOS=darwin go build $(LDFLAGS) -o $(PROG)-osx-$(ARCH) GOARCH=$(ARCH) GOOS=darwin go build $(LDFLAGS) -o $(PROG)-osx-$(ARCH)
linux: linux:
GO111MODULE=on GOARCH=$(ARCH) GOOS=linux go build $(LDFLAGS) -o $(PROG)-linux-$(ARCH) GOARCH=$(ARCH) GOOS=linux go build $(LDFLAGS) -o $(PROG)-linux-$(ARCH)
alpine: alpine:
GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build \ CGO_ENABLED=0 GOOS=linux go build \
-a -installsuffix cgo \ -a -installsuffix cgo \
$(LDFLAGS) -o $(PROG)-linux-$(ARCH) $(LDFLAGS) -o $(PROG)-linux-$(ARCH)
static: static:
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) \ CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) \
go build $(CFLAGS) \ go build $(CFLAGS) \
-a $(LDFLAGS_STATIC) \ -a $(LDFLAGS_STATIC) \
-o $(PROG)-linux-$(ARCH) -o $(PROG)-linux-$(ARCH)
test: test:
GO111MODULE=on go test -v go test -v
cd ../../pkg/api/ && GO111MODULE=on go test -v cd ../../pkg/api/ && GO111MODULE=on go test -v
cd ../../pkg/caches/ && GO111MODULE=on go test -v cd ../../pkg/caches/ && GO111MODULE=on go test -v
cd ../../pkg/sources/birdwatcher && GO111MODULE=on go test -v cd ../../pkg/sources/birdwatcher && GO111MODULE=on go test -v