Skip to content

Commit

Permalink
feat: improve Docker script toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
ozline committed Dec 7, 2023
1 parent 17dfccf commit bdf2b25
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ $(SERVICES):
cd $(CMD)/$(service) && sh build.sh
cd $(CMD)/$(service)/output && cp -r . $(OUTPUT_PATH)/$(service)
@echo "$(PERFIX) Build $(service) target completed"
ifndef autorun
@echo "$(PERFIX) Automatic run server"
sh entrypoint.sh $(service)
endif

# mock
.PHONY: $(MOCKS)
Expand All @@ -46,7 +49,7 @@ clean:
build-all:
@for var in $(SERVICES); do \
echo "$(PERFIX) building $$var service"; \
make $$var ci=1; \
make $$var autorun=1; \
done

# use docker instead to run projects
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20 AS builder
FROM golang:1.21 AS builder

ENV TZ Asia/Shanghai
ENV CGO_ENABLED 0
Expand All @@ -21,7 +21,7 @@ ENV TZ Asia/Shanghai
ENV service api

RUN apk update
RUN apk add --no-cache ffmpeg
# RUN apk add --no-cache ffmpeg

WORKDIR /app
COPY --from=builder /app/output /app/output
Expand Down
17 changes: 17 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# This script will log in to Aliyun Container Registry and push the image up.
# You first need to obtain the password for the account, otherwise you cannot push.

set -e

VERSION="latest"
DIR=$(pwd)

docker_image="registry.cn-hangzhou.aliyuncs.com/west2-online/fzuhelper-server:$VERSION"

# login, only need to login once, then you can comment out this sentence.
docker login registry.cn-hangzhou.aliyuncs.com [email protected]

# push image
docker buildx build --platform linux/amd64 -t $docker_image -f Dockerfile ../. --push
6 changes: 6 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/sh

# This file will serve as the entry point for the container.
# During the image building process, this file will be renamed to docker-entrypoint.sh.
# When the container starts, this shell script will be called to initiate the services within the container.

# THIS SCRIPT SHOULD NOT BE MANUALLY EXECUTED.

CONFIG_PATH="./config/config.yaml"

function read_key() {
Expand Down
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/sh

# After we use "make xxx" to build a certain service, the makefile will automatically execute this script.

# THIS SCRIPT SHOULD NOT BE MANUALLY EXECUTED.

SERVICE=$1
OUTPUT_PATH="./output"
CONFIG_PATH="./config/config.yaml"
Expand Down

0 comments on commit bdf2b25

Please sign in to comment.