Skip to content

Commit

Permalink
Add Swift Config
Browse files Browse the repository at this point in the history
  • Loading branch information
iyannsch committed Jun 19, 2024
1 parent ddbdafa commit 8044b64
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 3 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ jobs:
matrix:
docker-context: ['.']
include:
- docker-file: images/java-17/ToolDockerfile
image-name: ghcr.io/ls1intum/theia/java-17
- docker-file: images/java17-21/ToolDockerfile
image-name: ghcr.io/ls1intum/theia/java17-21
- docker-file: images/swift/ToolDockerfile
image-name: ghcr.io/ls1intum/theia/swift
build-args: |
"BUILDER_IMAGE"=swift:5.9.2-focal"
"RUNTIME_IMAGE=swift:5.9.2-focal"
"SWIFTLINT_VERSION=0.54.0"
uses: ls1intum/.github/.github/workflows/build-and-push-docker-image.yml@main
with:
docker-file: ${{ matrix.docker-file }}
Expand Down
11 changes: 11 additions & 0 deletions images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

We use Theia to provide students with programming environments tailored to their course`s needs. Instructors can choose a fitting Theia Blueprint (=Theia IDE Image) in Artemis. This repository contains the build tooling for creating those images.

Matching Artemis' programming environments, the following images are available:
- [ ] Java 17-21
- [ ] Kotlin
- [ ] Python
- [ ] C
- [ ] Haskell
- [ ] VHDL
- [ ] Assembler
- [x] Swift
- [ ] Ocaml

## Structure of Images
Our used Theia IDE Images are built in 3 steps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ COPY images/java-17/package.json .
RUN yarn --pure-lockfile && \
yarn download:plugins

# Builder stage to
# Assemble the application
FROM node:18-bullseye-slim as final-ide

WORKDIR /home/theia
Expand Down
File renamed without changes.
122 changes: 122 additions & 0 deletions images/swift/ToolDockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Swift requires builder and runtime images overwritten by workflow
ARG BUILDER_IMAGE=swift:focal
ARG RUNTIME_IMAGE=swift:focal

# Load the base-ide image, only copy from here
FROM ghcr.io/ls1intum/theia/base as base-ide

# Load the plugin image, only copy from here
FROM node:18-bullseye as plugin-image

WORKDIR /home/theia

# Configure to skip download of puppeteer
ENV PUPPETEER_SKIP_DOWNLOAD true

# Copy required configuration files
COPY yarn.lock yarn.lock

# Copy image specific files - this should overwrite the default files from the repository
# WARNING: This needs to be adapted to the specific image
COPY images/swift/package.json .

# Remove unnecesarry files for the browser application
# Download plugins and build application production mode
# Use yarn autoclean to remove unnecessary files from package dependencies
RUN yarn --pure-lockfile && \
yarn download:plugins

# Prepare Swift Application
# Adapted from https://github.com/ls1intum/artemis-swift-swiftlint-docker/blob/main/Dockerfile
FROM ${BUILDER_IMAGE} as builder

RUN apt-get update && apt-get install -y \
libcurl4-openssl-dev \
libxml2-dev \
&& rm -r /var/lib/apt/lists/*

RUN git clone https://github.com/realm/SwiftLint.git
WORKDIR /SwiftLint

# Default SwiftLint version - will be overwritten by the GH action
ARG SWIFTLINT_VERSION=0.53.0
RUN git checkout ${SWIFTLINT_VERSION}

RUN swift package update
ARG SWIFT_FLAGS="-c release -Xswiftc -static-stdlib -Xlinker -lCFURLSessionInterface -Xlinker -lCFXMLInterface -Xlinker -lcurl -Xlinker -lxml2 -Xswiftc -I. -Xlinker -fuse-ld=lld -Xlinker -L/usr/lib/swift/linux"
RUN swift build ${SWIFT_FLAGS} --product swiftlint
RUN mkdir -p /executables
RUN install -v `swift build ${SWIFT_FLAGS} --show-bin-path`/swiftlint /executables

# Assemble the application
FROM ${RUNTIME_IMAGE} as final-ide

# Required by Swift
RUN apt-get update && apt-get install -y \
libcurl4 \
libxml2 \
&& rm -r /var/lib/apt/lists/*

WORKDIR /home/theia

# Copy IDE files
COPY --from=base-ide /home/theia/applications/browser/lib/backend /home/theia/applications/browser/lib/backend
COPY --from=base-ide /home/theia/applications/browser/ /home/theia/applications/browser/

# Copy plugins
COPY --from=base-ide /home/theia/plugins /home/theia/plugins
COPY --from=plugin-image /home/theia/plugins /home/theia/plugins

# Create theia user and directories
# Application will be copied to /home/theia
# Default workspace is located at /home/project
RUN adduser --system --group theia
RUN chmod g+rw /home && \
mkdir -p /home/project && \
chown -R theia:theia /home/theia && \
chown -R theia:theia /home/project

# Copy dependencies from builder image
COPY --from=builder /usr/lib/libsourcekitdInProc.so /usr/lib
COPY --from=builder /usr/lib/swift/linux/libBlocksRuntime.so /usr/lib
COPY --from=builder /usr/lib/swift/linux/libdispatch.so /usr/lib
COPY --from=builder /usr/lib/swift/linux/libswiftCore.so /usr/lib
COPY --from=builder /executables/* /usr/bin

# Copy node from plugin-image as it is required for Theia
COPY --from=plugin-image /usr/local/bin/node /usr/local/bin/
COPY --from=plugin-image /usr/local/lib/node_modules/ /usr/local/lib/node_modules/
COPY --from=plugin-image /usr/local/lib/node_modules/ /home/theia/node_modules/
COPY --from=plugin-image /home/theia/node_modules/ /home/theia/node_modules/

# Create a symbolic link to the node_modules directory
RUN ln -s /home/theia/node_modules /home/theia/applications/browser/node_modules.asar

# Install required tools for tool creation and terminal usage: wget, apt-transport-https, update & upgrade packages, bash
RUN apt-get update && \
apt-get install -y wget apt-transport-https bash && \
apt-get upgrade -y

# Specify default shell for Theia and the Built-In plugins directory
ENV SHELL=/bin/bash \
THEIA_DEFAULT_PLUGINS=local-dir:/home/theia/plugins

# Use installed git instead of dugite
ENV USE_LOCAL_GIT true

# Print Installed Swift & SwiftLint Version
RUN swift --version
RUN swiftlint version

ENV HOME /home/theia
EXPOSE 3000

# Switch to Theia user
USER theia
WORKDIR /home/theia/applications/browser

# Launch the backend application via node
ENTRYPOINT [ "node", "/home/theia/applications/browser/lib/backend/main.js" ]

# Arguments passed to the application
CMD [ "/home/project", "--hostname=0.0.0.0" ]
43 changes: 43 additions & 0 deletions images/swift/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"private": true,
"version": "1.50.100",
"license": "MIT",
"author": "Rob Moran <[email protected]>",
"homepage": "https://github.com/eclipse-theia/theia-blueprint#readme",
"bugs": {
"url": "https://github.com/eclipse-theia/theia/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/eclipse-theia/theia-blueprint.git"
},
"engines": {
"yarn": ">=1.7.0 <2",
"node": ">=12.14.1"
},
"devDependencies": {
"@theia/cli": "1.50.1",
"node-pty": "1.0.0"
},
"scripts": {
"clean": "lerna run clean && rimraf node_modules",
"build:extensions": "lerna run --scope=\"theia-ide*ext\" build",
"download:plugins": "theia download:plugins --rate-limit=15 --parallel=false --ignore-errors"
},
"theiaPluginsDir": "plugins",
"theiaPlugins": {
"swift-language-basics": "https://open-vsx.org/api/vscode/swift/1.88.1/file/vscode.swift-1.88.1.vsix",
"swift": "https://open-vsx.org/api/sswg/swift-lang/1.10.2/file/sswg.swift-lang-1.10.2.vsix",
"swiftlint-vsc": "https://open-vsx.org/api/vknabel/vscode-swiftlint/1.8.4/file/vknabel.vscode-swiftlint-1.8.4.vsix"
},
"theiaPluginsExcludeIds": [
"ms-vscode.js-debug-companion",
"VisualStudioExptTeam.vscodeintellicode",
"vscode.builtin-notebook-renderers",
"vscode.extension-editing",
"vscode.github",
"vscode.github-authentication",
"vscode.ipynb",
"vscode.microsoft-authentication"
]
}

0 comments on commit 8044b64

Please sign in to comment.