Skip to content

Commit

Permalink
build!: Remove non-Linux binaries from the image and fix image buildi…
Browse files Browse the repository at this point in the history
…ng on Mac ARM (#7668)

* build: Support image building on Mac ARM

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

* Pass GOOS and GOARCH explicitly

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

* Retrigger CI pipeline

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

* Remove windows and mac binaries in the image

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

* Update download handler registration

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

* Inject arch to env var via webpack

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

* Fix lint

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

* Add BUILD_ALL_CLIS env flag for make release-cli

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

* Run in release-cli target directly

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>
  • Loading branch information
terrytangyuan authored Nov 19, 2021
1 parent 0c0bc1f commit 8e8a1de
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 43 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ jobs:
env:
NODE_ENV: production
NODE_ONLINE_ENV: online
HOST_ARCH: amd64
working-directory: ui/
- name: Run ESLint
run: yarn lint
Expand Down
8 changes: 1 addition & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ADD ["ui/", "."]

ARG ARGO_VERSION=latest
ENV ARGO_VERSION=$ARGO_VERSION
RUN NODE_ENV='production' NODE_ONLINE_ENV='online' yarn build
RUN HOST_ARCH='amd64' NODE_ENV='production' NODE_ONLINE_ENV='online' NODE_OPTIONS=--max_old_space_size=8192 yarn build

####################################################################################################
# Argo CD Build stage which performs the actual build of Argo CD binaries
Expand All @@ -115,12 +115,6 @@ COPY . .
COPY --from=argocd-ui /src/dist/app /go/src/github.com/argoproj/argo-cd/ui/dist/app
RUN make argocd-all

ARG BUILD_ALL_CLIS=true
RUN if [ "$BUILD_ALL_CLIS" = "true" ] ; then \
make BIN_NAME=argocd-darwin-amd64 GOOS=darwin argocd-all && \
make BIN_NAME=argocd-windows-amd64.exe GOOS=windows argocd-all \
; fi

####################################################################################################
# Final image
####################################################################################################
Expand Down
2 changes: 0 additions & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
####################################################################################################
FROM argocd-base
COPY argocd /usr/local/bin/
COPY argocd-darwin-amd64 /usr/local/bin/
COPY argocd-windows-amd64.exe /usr/local/bin/

USER root
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-server
Expand Down
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ cli-local: clean-debug
.PHONY: release-cli
release-cli: clean-debug image
docker create --name tmp-argocd-linux $(IMAGE_PREFIX)argocd:$(IMAGE_TAG)
make BIN_NAME=argocd-darwin-amd64 GOOS=darwin argocd-all
make BIN_NAME=argocd-windows-amd64.exe GOOS=windows argocd-all
docker cp tmp-argocd-linux:/usr/local/bin/argocd ${DIST_DIR}/argocd-linux-amd64
docker cp tmp-argocd-linux:/usr/local/bin/argocd-darwin-amd64 ${DIST_DIR}/argocd-darwin-amd64
docker cp tmp-argocd-linux:/usr/local/bin/argocd-windows-amd64.exe ${DIST_DIR}/argocd-windows-amd64.exe
docker rm tmp-argocd-linux

.PHONY: test-tools-image
Expand All @@ -235,7 +235,7 @@ manifests: test-tools-image
# consolidated binary for cli, util, server, repo-server, controller
.PHONY: argocd-all
argocd-all: clean-debug
CGO_ENABLED=0 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${BIN_NAME} ./cmd
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${BIN_NAME} ./cmd

.PHONY: server
server: clean-debug
Expand All @@ -261,8 +261,6 @@ image:
find ./ui/dist -type f -not -name gitkeep -delete
docker run -v ${CURRENT_DIR}/ui/dist/app:/tmp/app --rm -t argocd-ui sh -c 'cp -r ./dist/app/* /tmp/app/'
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd ./cmd
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-darwin-amd64 ./cmd
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-windows-amd64.exe ./cmd
ln -sfn ${DIST_DIR}/argocd ${DIST_DIR}/argocd-server
ln -sfn ${DIST_DIR}/argocd ${DIST_DIR}/argocd-application-controller
ln -sfn ${DIST_DIR}/argocd ${DIST_DIR}/argocd-repo-server
Expand All @@ -277,10 +275,8 @@ endif
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)argocd:$(IMAGE_TAG) ; fi

.PHONY: armimage
# The "BUILD_ALL_CLIS" argument is to skip building the CLIs for darwin and windows
# which would take a really long time.
armimage:
docker build -t $(IMAGE_PREFIX)argocd:$(IMAGE_TAG)-arm . --build-arg BUILD_ALL_CLIS="false"
docker build -t $(IMAGE_PREFIX)argocd:$(IMAGE_TAG)-arm .

.PHONY: builder-image
builder-image:
Expand Down
19 changes: 2 additions & 17 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"regexp"
go_runtime "runtime"
"strings"
gosync "sync"
"time"
Expand Down Expand Up @@ -813,26 +814,10 @@ func registerDownloadHandlers(mux *http.ServeMux, base string) {
if err != nil {
log.Warnf("argocd not in PATH")
} else {
mux.HandleFunc(base+"/argocd-linux-amd64", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(base+"/argocd-linux-"+go_runtime.GOARCH, func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, linuxPath)
})
}
darwinPath, err := exec.LookPath("argocd-darwin-amd64")
if err != nil {
log.Warnf("argocd-darwin-amd64 not in PATH")
} else {
mux.HandleFunc(base+"/argocd-darwin-amd64", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, darwinPath)
})
}
windowsPath, err := exec.LookPath("argocd-windows-amd64.exe")
if err != nil {
log.Warnf("argocd-windows-amd64.exe not in PATH")
} else {
mux.HandleFunc(base+"/argocd-windows-amd64.exe", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, windowsPath)
})
}
}

func (s *ArgoCDServer) getIndexData() ([]byte, error) {
Expand Down
10 changes: 1 addition & 9 deletions ui/src/app/help/components/help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,9 @@ export const Help = () => (
<div className='columns large-4 small-6'>
<div className='help-box'>
<p>Want to download the CLI tool?</p>
<a href={`download/argocd-linux-amd64`} className='user-info-panel-buttons argo-button argo-button--base'>
<a href={`download/argocd-linux-${process.env.HOST_ARCH}`} className='user-info-panel-buttons argo-button argo-button--base'>
<i className='fab fa-linux ' /> Linux
</a>
&nbsp;
<a href={`download/argocd-darwin-amd64`} className='user-info-panel-buttons argo-button argo-button--base'>
<i className='fab fa-apple' /> macOS
</a>
&nbsp;
<a href={`download/argocd-windows-amd64.exe`} className='user-info-panel-buttons argo-button argo-button--base'>
<i className='fab fa-windows' /> Windows
</a>
</div>
</div>
<div className='columns large-4 small-6'>
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const config = {
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
'process.env.NODE_ONLINE_ENV': JSON.stringify(process.env.NODE_ONLINE_ENV || 'offline'),
'process.env.HOST_ARCH': JSON.stringify(process.env.HOST_ARCH || 'amd64'),
'SYSTEM_INFO': JSON.stringify({
version: process.env.ARGO_VERSION || 'latest'
})
Expand Down

0 comments on commit 8e8a1de

Please sign in to comment.