How to install VS Code in Alpine Linux - visual-studio-code

I have an operating environment that is Alpine linux only and I need to install VS Code. How can VS Code be run on Alpine Linux?

Dockerfile:
FROM node:14.19.0-alpine
RUN set -x \
&& sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
&& apk upgrade \
&& apk --no-cache add alpine-sdk bash libstdc++ libc6-compat \
&& npm config set python python3
RUN git clone --recursive https://github.com/cdr/code-server.git
RUN cd code-server
RUN yarn global add code-server
ENV PASSWORD=changeme
ENTRYPOINT code-server --bind-addr 0:8443
Commands:
docker build . -t vscode
docker run -d -e PASSWORD=111111 -p8443:8443 vscode:latest
http://hostname:8443

Download it in Flatpak repos, it will run natively in a Gnome SDK environment.
Use a self-hosted environment such as Theia (https://www.theia-ide.org/index.html) or coder-editor (https://coder.com/). I've never tried them, I use the Flatpak one, but they seem interesting (you can "build" your osn editor in a Node environment).

Apologies for necrobump, but as what Marco suggested, coder.com has moved to github
the software, code-server is quite litterally VSCode, as a web application, I have been using this for about half a year and it is quite well developed, Alpine support is still spotty but i recall getting a few releases to function well a while back when i ran Alpine as my main.

Related

Running sbt in a Docker Container

I am trying to use Github actions for my scala project and created a Docker workflow for it. Basically, I am trying to install sbt into my container and run the project.
Dockerfile looks like this:
FROM centos:centos8
ENV SCALA_VERSION 2.13.1
ENV SBT_VERSION 1.5.2
RUN yum install -y epel-release
RUN yum update -y && yum install -y wget
# INSTALL JAVA
RUN yum install -y java-11-openjdk
# INSTALL SBT
RUN wget http://dl.bintray.com/sbt/rpm/sbt-${SBT_VERSION}.rpm
RUN yum install -y sbt-${SBT_VERSION}.rpm
RUN wget -O /usr/local/bin/sbt-launch.jar http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/$SBT_VERSION/sbt-launch.jar
WORKDIR /root
EXPOSE 8080
RUN sbt compile
CMD sbt run
But when I push anything, I get the following error:
The command '/bin/sh -c wget http://dl.bintray.com/sbt/rpm/sbt-${SBT_VERSION}.rpm' returned a non-zero code: 8
When I check the link manually (by setting the sbt version), I see indeed bintray responds with 403 forbidden error but status.bintray.com tells all systems are operational.
Am I doing something wrong or is something wrong with bintray?
Forbidden doesnt mean non operational.
I think that url is incorrect as its not hosted on bintray rather jfrog, please see section on Centos which states
remove old Bintray repo file
https://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Linux.html

Install older package version in Alpine

So recently (5th September) the Alpine Linux package repo was updated to postgresql-client 12.4
I'm referencing version 12.3 in my Dockerfile (apk add postgresql-client=~12.3). Is it not possible to install that version now?
I'd like to update on my time and terms, why should I be forced to update now? Is there another repository I can add to use the older version?
Thanks
Unfortunately, Alpine packages are always updated in place to the latest version, and older versions are discarded. This could be painful, indeed...
Usually, when a package is updated, it's updated with all Alpine distro versions that it's compatible to. For example, postgresql-client was bumped to 12.4-r0 on edge, v3.12 and v3.11, but on Alpine v3.10 repos you'll still find 11.9-r0. In case this was enough, the old version could be installed from the desired repository, as long as it lasts, using:
apk add postgresql-client=11.9-r0 --repository=http://dl-cdn.alpinelinux.org/alpine/v3.10/main
However, since 12.3 doesn't live in the official Alpine repositories anymore, you could rely on an external Docker image, instead.
Luckily, the postgres official images has version tags, and you can find the desired Alpine image for 12.3:
$ wget -q https://registry.hub.docker.com/v1/repositories/postgres/tags -O - | jq -r '.[].name' | grep 12.3
12.3
12.3-alpine
Therefore, you can use FROM:postgres:12.3-alpine to get the desired version from.
In tougher cases, where the Alpine package version is updated, and couldn't be found in other images, the only resort may be building from source.
for example; the latest dnsmasq version ins 2.84-r0 at now, if you install 2.83-r0, will:
$ docker run --rm -ti alpine:3.13
$ apk add 'dnsmasq-dnssec==2.83-r0'
fetch https://mirrors.aliyun.com/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
fetch https://mirrors.aliyun.com/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
dnsmasq-dnssec-2.84-r0:
breaks: world[dnsmasq-dnssec=2.83-r0]
The best thing you can achieve is using repositories of the earlier releases, at the websiete https://pkgs.alpinelinux.org/packages to search the old version, will find 2.83-r0 in https://pkgs.alpinelinux.org/packages?name=dnsmasq&branch=v3.12.
so add the old repo
$ echo 'http://dl-cdn.alpinelinux.org/alpine/v3.12/main' >> /etc/apk/repositories
$ apk add 'dnsmasq-dnssec==2.83-r0'
fetch http://mirrors.aliyun.com/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://mirrors.aliyun.com/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/3) Installing gmp (6.2.0-r0)
(2/3) Installing nettle (3.5.1-r1)
(3/3) Installing dnsmasq-dnssec (2.83-r0)
Executing dnsmasq-dnssec-2.83-r0.pre-install
Executing busybox-1.31.1-r16.trigger
OK: 7 MiB in 17 packages
Another solution based on the answer of #valiano.
For upgrading postgresql to a newer version, it is recommended to use the higher version pg_dump binaries. But how to get these into your image?
This works for me:
Dockerfile:
ARG VERSION=10
ARG UPGRADE_VERSION=11
ARG TYPE
###############################################################
# Normal server
###############################################################
FROM postgres:${VERSION}-alpine AS server
RUN apk update \
&& apk add --upgrade apk-tools \
&& apk upgrade --available
COPY /rootfs/ /
###############################################################
# Upgrade version with upgrade executables
###############################################################
FROM postgres:${UPGRADE_VERSION}-alpine AS upgrade_version
RUN apk update \
&& apk add --upgrade apk-tools \
&& apk upgrade --available
###############################################################
# Add postgresql upgrade client executables to upgrade_server_layer
###############################################################
FROM server AS upgrade_server
RUN mkdir -p /usr/local/postgresql/upgrade
COPY --from=upgrade_version /usr/local/bin/pg* /usr/local/postgresql/upgrade/
###############################################################
# Final version
###############################################################
FROM ${TYPE}server AS final
Then build your normal server as:
docker build --build-arg TYPE= --build-arg VERSION=11 --build-arg UPGRADE_VERSION=12 -t my_normal_server:11 .
And a server with upgrade binaries, to make the dumpfile:
docker build --build-arg TYPE=upgrade_ --build-arg VERSION=10 --build-arg UPGRADE_VERSION=11 -t my_upgrade_server:10 .
Upgrade scenario if current version is postgresql 10 and you want to upgrade to 11:
Build an upgrade version and a normal version.
Stop the postgresql 10 container and replace it with the my_upgrade_version:10
Create a dumpfile with the /usr/local/postgresql/upgrade/pg_dump.
Create a new postgresql 11 container with my_normal_version:11 with access to the dumpfile and use pg_restore to restore the created dumpfile.
About making a dry single-point-of-entry for fixed package versions:
I use the following method, where I have an .env file where I store the PG major and minor version. I only need to update the .env-file entry with preferred version numbers and rebuild my images to upgrade the Postgres.
As long as the package is present with the corresponding version in the dockerhub and the PG version itself isn't deprecated by the alpine repositories or sth:
Step 1: Specify the PG version in .env file as single point of entry:
PG_MAJOR_VERSION=14
PG_MINOR_VERSION=5
Step 2: Reference the db-package inside the docker-compose:
services:
db:
image: postgres:${PG_MAJOR_VERSION}.${PG_MINOR_VERSION}-alpine
Step 3: Use the variables inside the Dockerfile itself if needed:
ARG RUBY_VERSION
ARG DISTRO_NAME
FROM ruby:${RUBY_VERSION}-${DISTRO_NAME}
# Need to define the args again:
ARG DISTRO_NAME
ARG PG_MAJOR_VERSION
RUN apk add --update build-base bash bash-completion libffi-dev tzdata postgresql$PG_MAJOR_VERSION-client postgresql$PG_MAJOR_VERSION-dev nodejs npm yarn
NB! The FROM clause loses the ARG-variables defined before it. Therefore if you need them later then you need to define them again after the FROM-clause. This issue is described in more detail in this Github issue
Depending on the packages you wish to install you can specify the minor version or other suffixes as needed (for ex for postgresql15-client-15.1-r0 and postgresql15-dev-15.1-r0: package etc)

"gcc": executable file not found in %PATH% when using mongo-go-driver

I want to use mongodb driver.But I get the following error:
go.mongodb.org/mongo-driver/vendor/github.com/DataDog/zstd
exec: "gcc": executable file not found in %PATH%
The issue is that your library depends on gcc to run.
1. Linux/Containers
If you are running in a container, you can try two options:
you can build your app without CGO with the following command:
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o yourBinary
You can try to install gcc into your container. If it is an alpine based container, run
RUN apk update && apk add --no-cache gcc
You could also need musl-dev package, but you should try without it first.
2. Windows
Since MacOS and most Linux distros come with GCC, I guess you could be using Windows. In this case, you need to install MinGW.
I know this is old but I ran into this problem too, About Alexey answer, on windows, you should install MinGW and add the path to win environment. You should follow this. In case MinGW did not work, you can install this one which worked perfectly for me on windows.

Yarn: How to upgrade yarn version using terminal?

How should yarn be upgraded to the latest version?
For macOS users, if you installed yarn via brew, you can upgrade it using the below command:
brew upgrade yarn
On Linux, just run the below command at the terminal:
$ curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
On Windows, upgrade with Chocolatey
choco upgrade yarn
Credits:
Added answers with the help of the below answers
https://stackoverflow.com/a/54147594/842607
https://stackoverflow.com/a/53710422/842607
npm install --global yarn
npm upgrade --global yarn
This should work.
Not remembering how i've installed yarn the command that worked for me was:
yarn policies set-version
This command updates the current yarn version to the latest stable.
From the documentation:
Note that this command also is the preferred way to upgrade Yarn - it will work no matter how you originally installed it, which might sometimes prove difficult to figure out otherwise.
Reference
On Linux, just run below command at terminal:
$ curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
After do this, close the current terminal and open it again. And then, run below command to check yarn current version:
$ yarn --version
yarn policies set-version
will download the latest stable release
Referenced yarn docs
https://yarnpkg.com/lang/en/docs/cli/policies/#toc-policies-set-version
For Windows users
I usually upgrade Yarn with Chocolatey.
choco upgrade yarn
npm install -g yarn - solved the issue when nothing happened running npm update --global yarn.
Alternative method to update yarn: curl --compressed -o- -L https://yarnpkg.com/install.sh | bash.
Mac users with homebrew can run brew upgrade yarn.
More details here and here.
Works on all OS's
yarn set version latest
yarn set version from sources
Worked without the second line for me, but it is in the documentation for some reason.
Reference
I had an outdated symlink that was preventing me from accessing the proper bin. I had also recently gone through a node upgrade which means a lot of my newer bins were available in a different folder with what i think was a lower priority
Here is what worked for me:
yarn -v
> 1.15.2
which yarn
> /Users/lfender/.yarn/bin/yarn
rm -rf /Users/lfender/.yarn/bin/yarn
npm uninstall --global yarn; npm install --global yarn
> + yarn#1.16.0
> added 1 package in 0.179s
which yarn
> /Users/lfender/.nvm/versions/node/v12.2.0/bin/yarn
yarn -v
> 1.16.0
If you are not using NVM, the location of your bin installs are likely to be unique to your system
From there, I've switched to doing yarn policies set-version as outlined here https://stackoverflow.com/a/55278430/1426788 to define my yarn version at the repo level
According to https://yarnpkg.com/getting-started/install#updating-to-the-latest-versions
yarn set version <version>
For example to upgrade yarn v1.22.4 to v1.22.10:
yarn set version 1.22.10
I updated yarn on my Ubuntu by running the following command from my terminal
curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
source:https://yarnpkg.com/lang/en/docs/cli/self-update
Add Yarn Package Directory:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Install Yarn:
sudo apt-get update && sudo apt-get install yarn
Please note that the last command will upgrade yarn to latest version if package already installed.
For more info you can check the docs: yarn installation
If you already have yarn 1.x and you want to upgrade to yarn 2. You need to do something a bit different:
yarn set version berry
Where berry is the code name for yarn version 2. See this migration guide here for more info.
I tried at first
yarn policies set-version
Then it directed me to run
yarn set version stable
You should implement them in order, the first command will download your current yarn version and update .yarnrc after that running the second command will upgrade yarn successfully to the latest stable version
I tried all of the above solutions in Jenkins pipeline which needs the latest yarn.
Finally, this worked for me.
Run yarn policies set-version in the git repo
This will generate .yarn/releases/yarn-X.X.X.js file and .yarnrc file. Push both of these files in the Git repo.
Now build and all the yarn commands will use the yarn-X.X.X version.
Note: This is helpful when you don't have root access to npm install -g yarn.
npm i -g yarn
This should update your yarn version. Check version with yarn -v or yarn --version.
yarn policies set-version --rc
As per the yarn documentation to update yarn to latest version we should run the above command. Check version with yarn -v or yarn --version.
Ref : https://classic.yarnpkg.com/en/docs/cli/policies/#toc-policies-set-version
yarn policies set-version
Use the above command in powershell to upgrade your current yarn version to Latest.It will download the latest yarn release
yarn policies set-version
this upgraded my yarn version from 1.22.5 to 1.22.10
If You want to upgrade your yarn version from 1.22.5 to 1.22.10
yarn policies set-version
To upgrade to latest version of yarn, run the below command on your terminal.
"yarn set version latest -g"
This work for me to change yarn version 0.32 git to 1.22.5
https://www.codegrepper.com/code-examples/shell/yarn+0.32+git+ubuntu
Since you already have yarn installed and only want to upgrade/update. you can simply use
yarn self-update
Find ref here https://yarnpkg.com/en/docs/cli/self-update

Docker file for building code cloned from git

I've cloned a copy of FreeCAD from github and I'm trying to create a docker file so that I can develop it locally on my machine.
The objectives being that:
I have a local copy of the code from git on my machine
I can make modifications to the code
I can build debug and release image (do I need to create two separate images?)
Have access to the code on my machine, so that I can use git for source control
This is the content of my Dockerfile:
# Get base image
FROM phusion/baseimage
# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]
# Get the build pre-requisites
RUN apt-get update
RUN apt-get install -y build-essential cmake python python-matplotlib libtool
RUN apt-get install -y libcoin80-dev libsoqt4-dev
RUN apt-get install -y libxerces-c-dev libboost-dev libboost-filesystem-dev
RUN apt-get install -y libboost-regex-dev
RUN apt-get install -y libboost-program-options-dev libboost-signals-dev
RUN apt-get install -y libboost-thread-dev libboost-python-dev libqt4-dev
RUN apt-get install -y libqt4-opengl-dev qt4-dev-tools python-dev
RUN apt-get install -y python-pyside pyside-tools
RUN apt-get install -y liboce*-dev oce-draw
RUN apt-get install -y libeigen3-dev libqtwebkit-dev libshiboken-dev
RUN apt-get install -y libpyside-dev libode-dev swig libzipios++-dev
RUN apt-get install -y libfreetype6 libfreetype6-dev
# to make Coin to support additional image file formats
RUN apt-get install -y libsimage-dev
# to register your installed files into your system's package manager, so yo can easily uninstall later
RUN apt-get install -y checkinstall
# needed for the 2D Drafting module
RUN apt-get install -y python-qt4 python-pivy
# doxygen and libcoin80-doc (if you intend to generate source code documentation)
RUN apt-get install -y doxygen libcoin80-doc
# libspnav-dev (for 3Dconnexion devices support like the Space Navigator or Space Pilot)
RUN apt-get install -y libspnav-dev
# CMAke related issue for compiling on Ubuntu Xenial: http://forum.freecadweb.org/viewtopic.php?f=4&t=16292
RUN apt-get install -y libmedc-dev
RUN apt-get install -y libvtk6-dev
RUN apt-get install -y libproj-dev
# Get git
RUN apt-get install -y git
RUN git clone https://github.com/FreeCAD/FreeCAD.git freecad
RUN cd freecad
RUN mkdir freecad-debug
RUN cd freecad-debug
# command below is just a diagnostic to let me know wth I am (output is: /)
# RUN pwd
RUN cmake ../ -DFREECAD_USE_EXTERNAL_PIVY=1 -DCMAKE_BUILD_TYPE=Debug .
#cmake -DFREECAD_USE_EXTERNAL_PIVY=1 -DCMAKE_BUILD_TYPE=Release .
RUN make
I attempt to build the image using the following command:
docker build -tag freeCAD-my-fork .
Everything works until I get to the first cmake invocation. I then get the following error:
CMake Error: The source directory "/" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
The command '/bin/sh -c cmake ../ -DFREECAD_USE_EXTERNAL_PIVY=1 -DCMAKE_BUILD_TYPE=Debug .' returned a non-zero code: 1
I placed a RUN pwd in my Dockerfile, so I could find where the cmake command was being run from, and I was surprised to find that it was been run from the root directory.
I thought the issue was being caused by my use of relative and that it would be fixed by absolute paths - however specifying /path/to/my/copy/freecad when cloning etc, the issue remains.
How can I write my Dockerfile so that it achieves the objectives outlined above (stated at the beginning of my question)?
Default WORKDIR in docker is "/".All docker commands will be executed in that directory.There are two option either you change WORKDIR(https://docs.docker.com/engine/reference/builder/#workdir) or execute everything in one layer(In one RUN command).I have taken second approach.
Cloning and Building source code both executed in One layer of docker.
RUN git clone https://github.com/FreeCAD/FreeCAD.git freecad \
&& cd freecad \
&& mkdir freecad-debug \
&& cd freecad-debug \
&& cmake ../ -DFREECAD_USE_EXTERNAL_PIVY=1 -DCMAKE_BUILD_TYPE=Debug . \
&& make
You should install all your dependencies using run as you do but the actual building and copying of source code files should not happen when you build your image but when you run a container.
This way you can reuse your image for as many builds as you like.
Write a script with the build commands and copy it over to your image. Then in the CMD part of the dockerfile run that script.
To share the git project with the container you can mount your local files with docker run -v hostpath:containerpath imagename. That way any files in hostpath will be visible to the container at containerpath and vice versa. Alternatively you could also git clone from the script which is invoked by CMD but then you have to expose the build somehow to your host (some mounted volume again).