wails icon indicating copy to clipboard operation
wails copied to clipboard

Add devcontainers support

Open doxometrist opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

small developer QoL feature - add devcontainers recommended support.

Describe the solution you'd like

An easy way to get started using the vscode devcontainers setup.

This requires a setup with both golang and nodejs with reasonable versions.

I hoped to get a simple setup (file contents shown below). Due to version of node installed from 'apt-get install' I ended up with old Node 16 which causes this issue: `myproject# wails dev Wails CLI v2.8.2

Executing: go mod tidy • Generating bindings: Done. • Installing frontend dependencies: Done. • Compiling frontend:
> [email protected] build > tsc && vite build

file:///workspaces/wails-test/myproject/frontend/node_modules/vite/bin/vite.js:7
    await import('source-map-support').then((r) => r.default.install())
    ^^^^^

SyntaxError: Unexpected reserved word
    at Loader.moduleStrategy (internal/modules/esm/translators.js:133:18)
    at async link (internal/modules/esm/module_job.js:42:21)
npm ERR! code 1
npm ERR! path /workspaces/wails-test/myproject/frontend
npm ERR! command failed
npm ERR! command sh -c tsc && vite build

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2024-05-12T21_44_27_104Z-debug.log

ERROR exit status 1`

I wasn't sure whether to raise this as a feature request or a bug.

Describe alternatives you've considered

Trying to make this Dockerfile to work: `FROM golang:1.22.3-bullseye

RUN apt-get update

Install necessary packages

RUN apt-get update && apt-get install -y curl git bash nodejs npm &&
rm -rf /var/lib/apt/lists/*

Setup environment variables for Go

ENV GOPATH=/go ENV PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

RUN go install github.com/wailsapp/wails/v2/cmd/wails@latest

RUN apt -y install nsis

RUN apt -y install libgtk-3-dev libwebkit2gtk-4.0-dev

RUN wails doctor >doctor_out.txt

Setup working directory

WORKDIR /workspace

Port exposed for web server (adjust if different port is needed)

EXPOSE 3000

Keep container running (useful for dev containers)

CMD ["sleep", "infinity"] `

Additional context

Devcontainer.json { "name": "Go and Node.js Dev Container", "build": { "dockerfile": "Dockerfile", "context": ".." }, "customizations": { "settings": { "terminal.integrated.shell.linux": "/bin/bash" }, "extensions": [ "golang.go", "dbaeumer.vscode-eslint" ] }, "forwardPorts": [ 3000 ], "postCreateCommand": "echo 'Container ready!'", "remoteUser": "root" }

doxometrist avatar May 12 '24 21:05 doxometrist

Your dockerfile could be cleaned up to something like:

FROM node:20.0-bullseye-slim

# install dependencies
RUN apt-get update && \
    apt-get install -y \
    build-essential \
    git \
    libgtk-3-dev \
    libwebkit2gtk-4.0-dev \
    nsis \
    wget \
    zsh \
    && rm -rf /var/lib/apt/lists/*

# setup zsh and oh-my-zsh
RUN git clone --single-branch --depth 1 https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
RUN cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
RUN chsh -s /bin/zsh

# install go 1.22.0
ARG GO_VERSION=1.22.0
RUN wget https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz \
    && tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz \
    && rm go${GO_VERSION}.linux-amd64.tar.gz

# add go to path
ENV PATH=$PATH:/usr/local/go/bin
# set go path
ENV GOPATH=/usr/local/go

# install wails
RUN go install github.com/wailsapp/wails/v2/cmd/wails@latest

# make sure wails runs correctly
RUN wails doctor

I got a dev container for wails at https://github.com/mateothegreat/wails-devcontainer. Hope that helps!

mateothegreat avatar May 18 '24 06:05 mateothegreat

thanks, this worked!

doxometrist avatar May 18 '24 21:05 doxometrist

I'd love to know more about this. Is it vscode only? I'm wondering if it might be useful to "generate" a dev container.

leaanthony avatar May 18 '24 23:05 leaanthony

I only used with vscode. should be possible to generate a devcontainer in principle

doxometrist avatar May 28 '24 21:05 doxometrist