Skip to content

Commit ceb366d

Browse files
authored
Merge pull request #6228 from benz0li/add-dev-containers
Add Dev Container Configuration Files
2 parents 9255cb7 + 20b14c0 commit ceb366d

File tree

17 files changed

+592
-0
lines changed

17 files changed

+592
-0
lines changed

.devcontainer/.gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
*
2+
3+
!/assets/
4+
!/assets/cradles/
5+
!/assets/cradles/cabal/
6+
!/assets/cradles/stack/
7+
!/assets/screenshots/
8+
!/bind-mounts/
9+
!/conf/
10+
!/conf/etc/
11+
!/conf/etc/stack/
12+
!/ghc-*/
13+
!/scripts/
14+
!/scripts/usr/
15+
!/scripts/usr/local/
16+
!/scripts/usr/local/bin/
17+
18+
!/assets/cradles/cabal/hie.yaml
19+
!/assets/cradles/stack/hie.yaml
20+
!/assets/screenshots/manageHLS.png
21+
!/conf/etc/stack/config.yaml
22+
!/ghc-*/devcontainer.json
23+
!/scripts/usr/local/bin/*.sh
24+
25+
!/devcontainer.json
26+
!/GHC.Dockerfile
27+
!/LICENSE
28+
!/README.md
29+
30+
!.gitignore
31+
!.keep

.devcontainer/GHC.Dockerfile

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
ARG BUILD_ON_IMAGE=glcr.b-data.ch/ghc/ghc-musl
2+
ARG GHC_VERSION=latest
3+
ARG HLS_VERSION
4+
ARG STACK_VERSION
5+
6+
ARG HLS_GHC_VERSION=${HLS_VERSION:+$GHC_VERSION}
7+
ARG HLS_SFX=/${HLS_GHC_VERSION:-all}/hls:${HLS_VERSION:-none}
8+
9+
ARG STACK_VERSION_OVERRIDE=${STACK_VERSION:-none}
10+
11+
FROM ${BUILD_ON_IMAGE}:${GHC_VERSION} as files
12+
13+
RUN mkdir /files
14+
15+
COPY conf /files
16+
COPY scripts /files
17+
18+
## Ensure file modes are correct
19+
RUN find /files -type d -exec chmod 755 {} \; \
20+
&& find /files -type f -exec chmod 644 {} \; \
21+
&& find /files/usr/local/bin -type f -exec chmod 755 {} \;
22+
23+
FROM glcr.b-data.ch/commercialhaskell/ssi:${STACK_VERSION_OVERRIDE} as ssi
24+
25+
FROM ${BUILD_ON_IMAGE}${HLS_SFX} as hls
26+
27+
FROM glcr.b-data.ch/ndmitchell/hlsi:latest as hlsi
28+
29+
FROM docker.io/koalaman/shellcheck:stable as sci
30+
31+
FROM ${BUILD_ON_IMAGE}:${GHC_VERSION}
32+
33+
COPY --from=files /files /
34+
35+
RUN sysArch="$(uname -m)" \
36+
## Ensure that common CA certificates
37+
## and OpenSSL libraries are up to date
38+
&& apk upgrade --no-cache ca-certificates openssl-dev \
39+
## Install yamllint
40+
&& apk add --no-cache yamllint \
41+
## Install pip
42+
&& apk add --no-cache py3-pip \
43+
## Install terminal multiplexers
44+
&& apk add --no-cache screen tmux \
45+
## Install hadolint
46+
&& case "$sysArch" in \
47+
x86_64) tarArch="x86_64" ;; \
48+
aarch64) tarArch="arm64" ;; \
49+
*) echo "error: Architecture $sysArch unsupported"; exit 1 ;; \
50+
esac \
51+
&& apiResponse="$(curl -sSL \
52+
https://api.github.com/repos/hadolint/hadolint/releases/latest)" \
53+
&& downloadUrl="$(echo "$apiResponse" | grep -e \
54+
"browser_download_url.*Linux-$tarArch\"" | cut -d : -f 2,3 | tr -d \")" \
55+
&& echo "$downloadUrl" | xargs curl -sSLo /usr/local/bin/hadolint \
56+
&& chmod 755 /usr/local/bin/hadolint \
57+
## Create folders in root directory
58+
&& mkdir -p /root/.local/bin \
59+
## Create folders in skeleton directory
60+
&& mkdir -p /etc/skel/.local/bin
61+
62+
## Update environment
63+
ARG USE_ZSH_FOR_ROOT
64+
ARG SET_LANG
65+
ARG SET_TZ
66+
67+
ENV TZ=${SET_TZ:-$TZ} \
68+
LANG=${SET_LANG:-$LANG}
69+
70+
## Change root's shell to ZSH
71+
RUN if [ -n "$USE_ZSH_FOR_ROOT" ]; then \
72+
apk add --no-cache zsh shadow; \
73+
fix-chsh.sh; \
74+
chsh -s /bin/zsh; \
75+
fi \
76+
## Update timezone if needed
77+
&& if [ "$TZ" != "" ]; then \
78+
apk add --no-cache tzdata; \
79+
echo "Setting TZ to $TZ"; \
80+
ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime \
81+
&& echo "$TZ" > /etc/timezone; \
82+
fi \
83+
## Add/Update locale if needed
84+
&& if [ "$LANG" != "C.UTF-8" ]; then \
85+
if [ -n "$LANG" ]; then \
86+
apk add --no-cache musl-locales musl-locales-lang; \
87+
fi; \
88+
sed -i "s/LANG=C.UTF-8/LANG=$LANG/" /etc/profile.d/*locale.sh; \
89+
sed -i "s/LANG:-C.UTF-8/LANG:-$LANG/" /etc/profile.d/*locale.sh; \
90+
sed -i "s/LC_COLLATE=C/LC_COLLATE=$LANG/" /etc/profile.d/*locale.sh; \
91+
sed -i "s/LC_COLLATE:-C/LC_COLLATE:-$LANG/" /etc/profile.d/*locale.sh; \
92+
fi
93+
94+
## Copy binaries as late as possible to avoid cache busting
95+
## Install Stack
96+
COPY --from=ssi /usr/local /usr/local
97+
## Install HLS
98+
COPY --from=hls /usr/local /usr/local
99+
## Install HLint
100+
COPY --from=hlsi /usr/local /usr/local
101+
## Install ShellCheck
102+
COPY --from=sci --chown=root:root /bin/shellcheck /usr/local/bin
103+
104+
ARG HLS_VERSION
105+
ARG STACK_VERSION
106+
107+
ARG STACK_VERSION_OVERRIDE=${STACK_VERSION}
108+
109+
ENV HLS_VERSION=${HLS_VERSION} \
110+
STACK_VERSION=${STACK_VERSION_OVERRIDE:-$STACK_VERSION}
111+
112+
RUN if [ "${GHC_VERSION%.*}" = "9.2" ]; then \
113+
if [ -f /usr/local/bin/stack ]; then \
114+
mv -f /usr/local/bin/stack /usr/bin/; \
115+
fi \
116+
fi

.devcontainer/LICENSE

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2023 Olivier Benz
2+
3+
The code in this directory is not part of Stack (the software) and, with the
4+
exceptions noted below, is distributed under the terms of the MIT License:
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
24+
This directory also contains code with other copyrights. The affected files,
25+
their copyrights and license statements are listed below.
26+
27+
--------------------------------------------------------------------------------
28+
scripts/fix-chsh.sh
29+
Copyright (c) Microsoft Corporation. All rights reserved.
30+
31+
Licensed under the MIT License. See
32+
https://github.com/devcontainers/features/blob/main/LICENSE for
33+
license information.
34+
35+
--------------------------------------------------------------------------------

.devcontainer/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Dev Containers
2+
3+
See [haskellstack.org](https://docs.haskellstack.org): Stack's code (advanced)
4+
\> Maintainers \> Dev Containers or
5+
[../doc/maintainers/devcontainers.md](../doc/maintainers/devcontainers.md)
6+
for more information.
7+
8+
## License
9+
10+
The code in this directory is not part of Stack (the software) and, with the
11+
exceptions noted in [LICENSE](LICENSE), is distributed under the terms of the
12+
MIT License.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cradle:
2+
multi:
3+
- path: "./Setup.hs"
4+
config:
5+
cradle:
6+
direct:
7+
arguments: []
8+
- path: "./"
9+
config:
10+
cradle:
11+
cabal:
12+
- path: "./src"
13+
component: "lib:stack"
14+
- path: "./app"
15+
component: "stack:exe:stack"
16+
- path: "./tests/integration"
17+
component: "stack:exe:stack-integration-test"
18+
- path: "./tests/unit"
19+
component: "stack:test:stack-unit-test"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cradle:
2+
multi:
3+
- path: "./Setup.hs"
4+
config:
5+
cradle:
6+
direct:
7+
arguments: []
8+
- path: "./"
9+
config:
10+
cradle:
11+
stack:
12+
- path: "./src"
13+
component: "stack:lib"
14+
- path: "./app"
15+
component: "stack:exe:stack"
16+
- path: "./tests/integration"
17+
component: "stack:exe:stack-integration-test"
18+
- path: "./tests/unit"
19+
component: "stack:test:stack-unit-test"

.devcontainer/bind-mounts/.keep

Whitespace-only changes.
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Use only the GHC available on the PATH
2+
system-ghc: true
3+
# Do not automatically install GHC when necessary
4+
install-ghc: false

.devcontainer/devcontainer.json

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"name": "Default",
3+
"build": {
4+
"dockerfile": "GHC.Dockerfile",
5+
"args": {
6+
"GHC_VERSION": "9.4.6",
7+
"HLS_VERSION": "2.1.0.0",
8+
"USE_ZSH_FOR_ROOT": "unset-to-use-ash",
9+
"SET_LANG": "C.UTF-8",
10+
"SET_TZ": ""
11+
}
12+
},
13+
14+
"onCreateCommand": "onCreateCommand.sh",
15+
"postCreateCommand": "cabal update",
16+
17+
"features": {
18+
"ghcr.io/devcontainers/features/common-utils:2": {
19+
"configureZshAsDefaultShell": true,
20+
"upgradePackages": false,
21+
"username": "vscode",
22+
"userUid": "automatic",
23+
"userGid": "automatic"
24+
}
25+
},
26+
27+
"customizations": {
28+
"vscode": {
29+
"extensions": [
30+
31+
"exiasr.hadolint",
32+
"GitHub.vscode-pull-request-github",
33+
"haskell.haskell",
34+
"mhutchie.git-graph",
35+
"mutantdino.resourcemonitor",
36+
"timonwong.shellcheck"
37+
],
38+
"settings": {
39+
"gitlens.showWelcomeOnInstall": false,
40+
"gitlens.showWhatsNewAfterUpgrades": false,
41+
"haskell.manageHLS": "PATH",
42+
"resmon.show.battery": false,
43+
"resmon.show.cpufreq": false
44+
}
45+
}
46+
},
47+
48+
// Set 'remoteUser' to 'root' to connect as root instead.
49+
"remoteUser": "vscode",
50+
"mounts": [
51+
"source=stack-default-home-vscode,target=/home/vscode,type=volume"
52+
// "source=${localWorkspaceFolder}/.devcontainer/bind-mounts/stack-default-home-vscode,target=/home/vscode,type=bind"
53+
],
54+
55+
// "remoteUser": "root",
56+
// "mounts": [
57+
// "source=stack-default-root,target=/root,type=volume"
58+
// // "source=${localWorkspaceFolder}/.devcontainer/bind-mounts/stack-default-root,target=/root,type=bind"
59+
// ],
60+
61+
// Pip: Install packages to the user site
62+
"remoteEnv": {
63+
"PIP_USER": "1"
64+
}
65+
}
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "GHC 9.6.2",
3+
"build": {
4+
"dockerfile": "../GHC.Dockerfile",
5+
"context": "..",
6+
"args": {
7+
"GHC_VERSION": "9.6.2",
8+
"USE_ZSH_FOR_ROOT": "unset-to-use-ash",
9+
"SET_LANG": "C.UTF-8",
10+
"SET_TZ": ""
11+
}
12+
},
13+
14+
"onCreateCommand": "onCreateCommand.sh",
15+
"postCreateCommand": "cabal update",
16+
17+
"features": {
18+
"ghcr.io/devcontainers/features/common-utils:2": {
19+
"configureZshAsDefaultShell": true,
20+
"upgradePackages": false,
21+
"username": "vscode",
22+
"userUid": "automatic",
23+
"userGid": "automatic"
24+
}
25+
},
26+
27+
"customizations": {
28+
"vscode": {
29+
"extensions": [
30+
31+
"exiasr.hadolint",
32+
"GitHub.vscode-pull-request-github",
33+
"mhutchie.git-graph",
34+
"mutantdino.resourcemonitor",
35+
"timonwong.shellcheck"
36+
],
37+
"settings": {
38+
"gitlens.showWelcomeOnInstall": false,
39+
"gitlens.showWhatsNewAfterUpgrades": false,
40+
"resmon.show.battery": false,
41+
"resmon.show.cpufreq": false
42+
}
43+
}
44+
},
45+
46+
// Set 'remoteUser' to 'root' to connect as root instead.
47+
"remoteUser": "vscode",
48+
"mounts": [
49+
"source=stack-ghc-9.6.2-home-vscode,target=/home/vscode,type=volume"
50+
// "source=${localWorkspaceFolder}/.devcontainer/bind-mounts/stack-ghc-9.6.2-home-vscode,target=/home/vscode,type=bind"
51+
],
52+
53+
// "remoteUser": "root",
54+
// "mounts": [
55+
// "source=stack-ghc-9.6.2-root,target=/root,type=volume"
56+
// // "source=${localWorkspaceFolder}/.devcontainer/bind-mounts/stack-ghc-9.6.2-root,target=/root,type=bind"
57+
// ],
58+
59+
// Pip: Install packages to the user site
60+
"remoteEnv": {
61+
"PIP_USER": "1"
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
#-------------------------------------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See https://github.com/devcontainers/features/blob/main/LICENSE for license information.
5+
#-------------------------------------------------------------------------------------------------------------------------
6+
#
7+
# Docs: https://github.com/devcontainers/features/tree/main/src/common-utils
8+
# Maintainer: The Dev Container spec maintainers
9+
10+
set -e
11+
12+
# Fixing chsh always asking for a password on alpine linux
13+
# ref: https://askubuntu.com/questions/812420/chsh-always-asking-a-password-and-get-pam-authentication-failure.
14+
if [ ! -f "/etc/pam.d/chsh" ] || ! grep -Eq '^auth(.*)pam_rootok\.so$' /etc/pam.d/chsh; then
15+
echo "auth sufficient pam_rootok.so" >> /etc/pam.d/chsh
16+
elif [[ -n "$(awk '/^auth(.*)pam_rootok\.so$/ && !/^auth[[:blank:]]+sufficient[[:blank:]]+pam_rootok\.so$/' /etc/pam.d/chsh)" ]]; then
17+
awk '/^auth(.*)pam_rootok\.so$/ { $2 = "sufficient" } { print }' /etc/pam.d/chsh > /tmp/chsh.tmp && mv /tmp/chsh.tmp /etc/pam.d/chsh
18+
fi

0 commit comments

Comments
 (0)