Skip to content

Commit 8d4770b

Browse files
Pive01whummer
andauthored
fix(Invoke): Fixed Windows Issue by shipping pre-built binaries for platforms (#51)
Co-authored-by: Waldemar Hummer <waldemar.hummer@gmail.com>
1 parent b5bebf7 commit 8d4770b

File tree

17 files changed

+134
-108
lines changed

17 files changed

+134
-108
lines changed

.github/workflows/build-push-docker.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
- name: Checkout repository
2323
uses: actions/checkout@v3
2424

25+
- name: Download binaries
26+
run: bash downloadBinaries.sh
27+
2528
- name: Set up Docker Buildx
2629
uses: docker/setup-buildx-action@v1
2730

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.17-alpine AS builder
1+
FROM golang:1.21-alpine AS builder
22
ENV CGO_ENABLED=0
33
WORKDIR /backend
44
COPY vm/go.* .
@@ -55,6 +55,7 @@ LABEL org.opencontainers.image.title="LocalStack" \
5555
com.docker.extension.changelog="https://github.com/localstack/localstack-docker-extension/blob/main/CHANGELOG.md"
5656

5757
COPY --from=builder /backend/bin/service /
58+
5859
COPY docker-compose.yaml .
5960
COPY metadata.json .
6061
COPY localstack.svg .
@@ -63,5 +64,10 @@ COPY --chmod=0755 scripts/windows/checkWSLOS.cmd /windows/checkWSLOS.cmd
6364
COPY --chmod=0755 scripts/windows/checkUser.cmd /windows/checkUser.cmd
6465
COPY --chmod=0755 scripts/darwin/checkUser.sh /darwin/checkUser.sh
6566
COPY --chmod=0755 scripts/linux/checkUser.sh /linux/checkUser.sh
67+
COPY --chmod=0755 binaries/windows/localstack-windows-amd.exe /windows/localstack-windows-amd.exe
68+
COPY --chmod=0755 binaries/darwin/localstack-darwin-amd /darwin/localstack-darwin-amd
69+
COPY --chmod=0755 binaries/darwin/localstack-darwin-arm /darwin/localstack-darwin-arm
70+
COPY --chmod=0755 binaries/linux/localstack-linux-arm /linux/localstack-linux-arm
71+
COPY --chmod=0755 binaries/linux/localstack-linux-amd /linux/localstack-linux-amd
6672

6773
CMD /service -socket /run/guest-services/extension-LocalStack.sock

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
IMAGE?=localstack/localstack-docker-desktop
2-
TAG?=0.5.2
2+
TAG?=0.5.3
33

44
BUILDER=buildx-multi-arch
55

66
INFO_COLOR = \033[0;36m
77
NO_COLOR = \033[m
88

99
build-extension: ## Build service image to be deployed as a desktop extension
10-
docker build --tag=$(IMAGE):$(TAG) .
10+
ls binaries/linux/localstack-* > /dev/null 2>&1 || ./downloadBinaries.sh
11+
docker build --tag=$(IMAGE):$(TAG) .
1112

1213
install-extension: build-extension ## Install the extension
1314
docker extension install $(IMAGE):$(TAG)

binaries/.gitkeep

Whitespace-only changes.

downloadBinaries.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
latest_version=$(curl -s https://api.github.com/repos/localstack/localstack-cli/releases/latest | grep "tag_name" | cut -d'"' -f4)
4+
version_number=$(echo "$latest_version" | grep -oP 'v(\d+\.\d+\.\d+)' | sed 's/v//')
5+
6+
wget "https://github.com/localstack/localstack-cli/releases/latest/download/localstack-cli-${version_number}-linux-amd64-onefile.tar.gz" -O localstack-cli-linux-amd64-onefile.tar.gz
7+
wget "https://github.com/localstack/localstack-cli/releases/latest/download/localstack-cli-${version_number}-linux-arm64-onefile.tar.gz" -O localstack-cli-linux-arm64-onefile.tar.gz
8+
wget "https://github.com/localstack/localstack-cli/releases/latest/download/localstack-cli-${version_number}-darwin-amd64-onefile.tar.gz" -O localstack-cli-darwin-amd64-onefile.tar.gz
9+
wget "https://github.com/localstack/localstack-cli/releases/latest/download/localstack-cli-${version_number}-darwin-arm64-onefile.tar.gz" -O localstack-cli-darwin-arm64-onefile.tar.gz
10+
wget "https://github.com/localstack/localstack-cli/releases/latest/download/localstack-cli-${version_number}-windows-amd64-onefile.zip" -O localstack-cli-windows-amd64-onefile.zip
11+
12+
mkdir ./binaries/linux
13+
tar -xzvf localstack-cli-linux-amd64-onefile.tar.gz -C ./binaries/linux && mv ./binaries/linux/localstack ./binaries/linux/localstack-linux-amd && rm localstack-cli-linux-amd64-onefile.tar.gz
14+
tar -xzvf localstack-cli-linux-arm64-onefile.tar.gz -C ./binaries/linux && mv ./binaries/linux/localstack ./binaries/linux/localstack-linux-arm && rm localstack-cli-linux-arm64-onefile.tar.gz
15+
16+
mkdir ./binaries/darwin
17+
tar -xzvf localstack-cli-darwin-amd64-onefile.tar.gz -C ./binaries/darwin && mv ./binaries/darwin/localstack ./binaries/darwin/localstack-darwin-amd && rm localstack-cli-darwin-amd64-onefile.tar.gz
18+
tar -xzvf localstack-cli-darwin-arm64-onefile.tar.gz -C ./binaries/darwin && mv ./binaries/darwin/localstack ./binaries/darwin/localstack-darwin-arm && rm localstack-cli-darwin-arm64-onefile.tar.gz
19+
20+
mkdir ./binaries/windows
21+
unzip localstack-cli-windows-amd64-onefile.zip -d ./binaries/windows && mv ./binaries/windows/localstack.exe ./binaries/windows/localstack-windows-amd.exe && rm localstack-cli-windows-amd64-onefile.zip
22+

metadata.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,23 @@
2222
"darwin": [
2323
{
2424
"path": "/darwin/checkUser.sh"
25+
},
26+
{
27+
"path": "/darwin/localstack-darwin-amd"
28+
},
29+
{
30+
"path": "/darwin/localstack-darwin-arm"
2531
}
2632
],
2733
"linux": [
2834
{
2935
"path": "/linux/checkUser.sh"
36+
},
37+
{
38+
"path": "/linux/localstack-linux-amd"
39+
},
40+
{
41+
"path": "/linux/localstack-linux-arm"
3042
}
3143
],
3244
"windows": [
@@ -35,6 +47,9 @@
3547
},
3648
{
3749
"path": "/windows/checkUser.cmd"
50+
},
51+
{
52+
"path": "/windows/localstack-windows-amd.exe"
3853
}
3954
]
4055
}

ui/src/components/Feedback/DownloadProgress/DownloadProgress.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface DownloadProgressProps {
2525

2626
export const DownloadProgress = ({ callback, imageName }: DownloadProgressProps): ReactElement => {
2727

28-
const ddClient = useDDClient();
28+
const { client: ddClient } = useDDClient();
2929
const [statusMap, setStatusMap] = useState<Map<string, string>>(new Map());
3030
const [isDone, setIsDone] = useState<boolean>(false);
3131
const percentage = Array.from(statusMap.entries())

ui/src/components/Header/Controller.tsx

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import {
1111
} from '../../services';
1212
import {
1313
DEFAULT_CONFIGURATION_ID,
14-
FLAGS,
1514
PRO_IMAGE,
1615
COMMUNITY_IMAGE,
16+
FLAGS_AS_STRING,
1717
} from '../../constants';
1818
import { LongMenu } from './Menu';
1919
import { DockerContainer, DockerImage } from '../../types';
2020
import { DownloadProgressDialog } from '../Feedback/DownloadProgressDialog';
2121
import { ProgressButton } from '../Feedback';
22-
import { generateCLIArgs } from '../../services/util/cli';
2322

2423
const EXCLUDED_ERROR_TOAST = ['INFO', 'WARN', 'DEBUG'];
2524

@@ -31,7 +30,7 @@ export const Controller = (): ReactElement => {
3130
const [downloadProps, setDownloadProps] = useState({ open: false, image: COMMUNITY_IMAGE });
3231
const [isStarting, setIsStarting] = useState<boolean>(false);
3332
const [isStopping, setIsStopping] = useState<boolean>(false);
34-
const ddClient = useDDClient();
33+
const { client: ddClient, getBinary } = useDDClient();
3534
const isRunning = data && data.State === 'running';
3635
const isUnhealthy = data && data.Status.includes('unhealthy');
3736
const tooltipLabel = isUnhealthy ? 'Unhealthy' : 'Healthy';
@@ -48,52 +47,44 @@ export const Controller = (): ReactElement => {
4847
}
4948
}, [isLoading]);
5049

51-
const buildHostArgs = () => {
52-
let location = 'LOCALSTACK_VOLUME_DIR=/tmp/localstack/volume';
53-
let homeDir = `HOME=/home/${user}`;
50+
const buildHostArgs = (): NodeJS.ProcessEnv => {
51+
let location = '/tmp/localstack/volume';
5452

5553
if (!hasSkippedConfiguration) {
5654
switch (ddClient.host.platform) {
5755
case 'win32':
58-
location = `LOCALSTACK_VOLUME_DIR=\\\\wsl$\\${os}\\home\\${user}\\.cache\\localstack\\volume`;
59-
homeDir = `HOME=\\\\wsl$\\${os}\\home\\${user}`;
56+
location = `\\\\wsl$\\${os}\\home\\${user}\\.cache\\localstack\\volume`;
6057
break;
6158
case 'darwin':
62-
location = `LOCALSTACK_VOLUME_DIR=/Users/${user}/Library/Caches/localstack/volume`;
63-
homeDir = `HOME=/Users/${user}`;
59+
location = `/Users/${user}/Library/Caches/localstack/volume`;
6460
break;
6561
default:
66-
location = `LOCALSTACK_VOLUME_DIR=/home/${user}/.cache/localstack/volume`;
67-
homeDir = `HOME=/home/${user}`;
62+
location = `/home/${user}/.cache/localstack/volume`;
6863
}
6964
}
70-
return ['-e', location, '-e', homeDir];
65+
return { LOCALSTACK_VOLUME_DIR: location };
7166
};
7267

73-
const normalizeArguments = async () => {
74-
const extendedFlag = FLAGS.map(x => x); // clone
75-
let isPro = false;
68+
const normalizeArguments = (): NodeJS.ProcessEnv => {
7669
const addedArgs = configData.configs.find(config => config.id === runningConfig)
7770
.vars.map(item => {
7871
if (item.variable === 'DOCKER_FLAGS') {
79-
extendedFlag[1] = FLAGS.at(1).slice(0, -1).concat(` ${item.value}'`);
80-
}
81-
if (item.variable === 'LOCALSTACK_AUTH_TOKEN') {
82-
isPro = true;
72+
return { [item.variable]: `${FLAGS_AS_STRING} ${item.value}` };
8373
}
8474

85-
return ['-e', `${item.variable}=${item.value}`];
86-
}).flat();
75+
return { [item.variable]: item.value };
76+
});
8777

88-
return [
89-
...extendedFlag,
90-
...buildHostArgs(),
91-
...addedArgs,
92-
...generateCLIArgs({ call: 'start', pro: isPro }),
93-
];
78+
return [...addedArgs, buildHostArgs()].reduce((acc, obj) => {
79+
const [key, value] = Object.entries(obj)[0];
80+
acc[key] = value;
81+
return acc;
82+
}, {} as NodeJS.ProcessEnv);
9483
};
9584

9685
const start = async () => {
86+
setIsStarting(true);
87+
9788
const images = await ddClient.docker.listImages() as [DockerImage];
9889

9990
const isPro = configData.configs.find(config => config.id === runningConfig)
@@ -112,10 +103,16 @@ export const Controller = (): ReactElement => {
112103
return;
113104
}
114105

115-
const args = await normalizeArguments();
106+
const args = normalizeArguments();
107+
108+
const binary = getBinary();
109+
if (!binary) {
110+
setIsStarting(false);
111+
return;
112+
}
116113

117-
setIsStarting(true);
118-
ddClient.docker.cli.exec('run', args, {
114+
ddClient.extension.host?.cli.exec(binary, ['start', '--no-banner', '-d'], {
115+
env: args,
119116
stream: {
120117
onOutput(data): void {
121118
const shouldDisplayError = !EXCLUDED_ERROR_TOAST.some(item => data.stderr?.includes(item)) && data.stderr;

ui/src/components/Header/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useDDClient } from '../../services';
55
import { Controller } from './Controller';
66

77
export const Header = (): ReactElement => {
8-
const ddClient = useDDClient();
8+
const { client: ddClient } = useDDClient();
99

1010
return (
1111
<AppBar

ui/src/components/Header/Menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const LongMenu = () => {
2020
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
2121
const [openModal, setOpenModal] = useState<boolean>(false);
2222
const [images, setImages] = useState<string[]>(['Loading...']);
23-
const ddClient = useDDClient();
23+
const { client: ddClient } = useDDClient();
2424

2525
const open = Boolean(anchorEl);
2626

0 commit comments

Comments
 (0)