chore(build): Optimize Docker build configuration and process, adjust task names
This commit is contained in:
@@ -9,7 +9,7 @@ concurrency:
|
|||||||
cancel-in-progress: false
|
cancel-in-progress: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-app:
|
build-images:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
@@ -42,12 +42,6 @@ jobs:
|
|||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
if: matrix.service_name == 'app'
|
|
||||||
uses: actions/setup-go@v4
|
|
||||||
with:
|
|
||||||
go-version: '1.24'
|
|
||||||
|
|
||||||
- name: Prepare version info
|
- name: Prepare version info
|
||||||
id: version
|
id: version
|
||||||
run: |
|
run: |
|
||||||
@@ -62,6 +56,20 @@ jobs:
|
|||||||
# 显示版本信息
|
# 显示版本信息
|
||||||
./scripts/get_version.sh info
|
./scripts/get_version.sh info
|
||||||
|
|
||||||
|
- name: Build Cache for Docker
|
||||||
|
uses: actions/cache@v4
|
||||||
|
id: cache
|
||||||
|
with:
|
||||||
|
path: go-build-cache
|
||||||
|
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}
|
||||||
|
|
||||||
|
- name: Inject go-build-cache
|
||||||
|
uses: reproducible-containers/buildkit-cache-dance@v3
|
||||||
|
with:
|
||||||
|
cache-source: go-build-cache
|
||||||
|
dockerfile: ${{ matrix.file }}
|
||||||
|
skip-extraction: ${{ steps.cache.outputs.cache-hit }}
|
||||||
|
|
||||||
- name: Build ${{ matrix.service_name }} Image
|
- name: Build ${{ matrix.service_name }} Image
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
@@ -79,3 +87,4 @@ jobs:
|
|||||||
${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:${{ steps.version.outputs.version }}
|
${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:${{ steps.version.outputs.version }}
|
||||||
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:cache
|
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:cache
|
||||||
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:cache,mode=max
|
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/weknora-${{ matrix.service_name }}:cache,mode=max
|
||||||
|
|
||||||
@@ -21,10 +21,9 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/re
|
|||||||
RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
|
RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
|
||||||
|
|
||||||
# Copy go mod and sum files
|
# Copy go mod and sum files
|
||||||
COPY go.mod .
|
COPY go.mod go.sum ./
|
||||||
COPY go.sum .
|
RUN --mount=type=cache,target=/go/pkg/mod go mod download
|
||||||
RUN go mod download
|
RUN --mount=type=cache,target=/go/pkg/mod cp -r /go/pkg/mod/github.com/yanyiwu/ /app/yanyiwu/
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Get version and commit info for build injection
|
# Get version and commit info for build injection
|
||||||
ARG VERSION_ARG
|
ARG VERSION_ARG
|
||||||
@@ -39,7 +38,8 @@ ENV BUILD_TIME=${BUILD_TIME_ARG}
|
|||||||
ENV GO_VERSION=${GO_VERSION_ARG}
|
ENV GO_VERSION=${GO_VERSION_ARG}
|
||||||
|
|
||||||
# Build the application with version info
|
# Build the application with version info
|
||||||
RUN make build-prod
|
COPY . .
|
||||||
|
RUN --mount=type=cache,target=/go/pkg/mod make build-prod
|
||||||
|
|
||||||
# Final stage
|
# Final stage
|
||||||
FROM alpine:3.17
|
FROM alpine:3.17
|
||||||
@@ -58,7 +58,7 @@ RUN mkdir -p /data/files && \
|
|||||||
|
|
||||||
# Copy migrate tool from builder stage
|
# Copy migrate tool from builder stage
|
||||||
COPY --from=builder /go/bin/migrate /usr/local/bin/
|
COPY --from=builder /go/bin/migrate /usr/local/bin/
|
||||||
COPY --from=builder /go/pkg/mod/github.com/yanyiwu /go/pkg/mod/github.com/yanyiwu/
|
COPY --from=builder /app/yanyiwu/ /go/pkg/mod/github.com/yanyiwu/
|
||||||
|
|
||||||
# Copy the binary from the builder stage
|
# Copy the binary from the builder stage
|
||||||
COPY --from=builder /app/config ./config
|
COPY --from=builder /app/config ./config
|
||||||
|
|||||||
Reference in New Issue
Block a user