Skip to content

Commit

Permalink
Refactor build configuration to use latest goreleaser version and opt…
Browse files Browse the repository at this point in the history
…imize platform combinations
  • Loading branch information
WangYihang committed Oct 2, 2024
1 parent 3934b41 commit 2c1f71b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4,540 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: v2.2.0
version: latest
args: build --snapshot --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -38,7 +38,7 @@ jobs:
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: v2.2.0
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71 changes: 36 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
# Stage 1: Builder
FROM golang:1.22.6-alpine AS builder

# Install necessary packages and tools
RUN apk add --no-cache git upx \
&& go install github.com/goreleaser/goreleaser/[email protected] \
&& go install github.com/air-verse/air@latest \
&& go install golang.org/x/tools/cmd/goimports@latest \
&& go install github.com/fzipp/gocyclo/cmd/gocyclo@latest \
&& go install github.com/go-critic/go-critic/cmd/gocritic@latest \
&& go install github.com/BurntSushi/toml/cmd/tomlv@latest \
&& go get -u github.com/go-bindata/go-bindata/... \
&& go install github.com/wangyihang/platypus/cmd/platypus-server@latest \
&& go install github.com/wangyihang/platypus/cmd/platypus-agent@latest \
&& go install github.com/wangyihang/platypus/cmd/platypus-admin@latest
FROM golang:1.23.2 AS builder

# # replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Install necessary golang packages and tools
RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.cn,direct
RUN go install github.com/goreleaser/goreleaser/v2@latest
RUN go install github.com/air-verse/air@latest
RUN go install golang.org/x/tools/cmd/goimports@latest
RUN go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
RUN go install github.com/go-critic/go-critic/cmd/gocritic@latest
RUN go install github.com/BurntSushi/toml/cmd/tomlv@latest

# Installs nvm (Node Version Manager)
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

# Download and install Node.js (you may need to restart the terminal)
RUN source ~/.nvm/nvm.sh \
&& nvm install 20 \
&& nvm alias default 20 \
&& nvm use default \
&& npm config set registry https://registry.npmmirror.com/ \
&& npm install -g yarn

# Set up the working directory
WORKDIR /app

# Copy source code
COPY . .

# Check if the current commit is tagged, and build accordingly
RUN if git describe --tags --exact-match >/dev/null 2>&1; then \
echo "Commit is tagged. Creating a release build."; \
goreleaser build --clean; \
else \
echo "Commit is not tagged. Creating a snapshot build."; \
goreleaser build --clean --snapshot; \
fi

# Stage 2: Final image
FROM ubuntu:24.04

# Copy necessary binaries from the builder stage
COPY --from=builder /go/bin/goreleaser /usr/local/bin/goreleaser
COPY --from=builder /go/bin/air /usr/local/bin/air
COPY --from=builder /go/bin/goimports /usr/local/bin/goimports
COPY --from=builder /go/bin/gocyclo /usr/local/bin/gocyclo
COPY --from=builder /go/bin/gocritic /usr/local/bin/gocritic
COPY --from=builder /go/bin/platypus-server /usr/local/bin/platypus-server
COPY --from=builder /go/bin/platypus-agent /usr/local/bin/platypus-agent
COPY --from=builder /go/bin/platypus-admin /usr/local/bin/platypus-admin
# Download golang dependencies
RUN /usr/local/go/bin/go mod download

# Download web dependencies
RUN source ~/.nvm/nvm.sh \
&& cd web/platypus \
&& yarn install \
&& yarn build

# Build the application
RUN goreleaser build --snapshot --clean --single-target
Loading

0 comments on commit 2c1f71b

Please sign in to comment.