Skip to content

Commit

Permalink
Feature/code editor (#2)
Browse files Browse the repository at this point in the history
Support for code-server based VSCode editor
  • Loading branch information
MarcusAhlfors authored Mar 2, 2024
1 parent e2f5a20 commit 341a984
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 101 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/DiploiBuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: DiploiBuild

on:
push:
branches:
- main
tags:
- 'v*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
INITIAL_PROJECT_IMAGE_NAME: ${{ github.repository }}-initial-project

jobs:

TemplateBuild:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the GitHub container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/arm64
pull: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

InitialProjectBuild:
needs: TemplateBuild
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.INITIAL_PROJECT_IMAGE_NAME }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the GitHub container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: InitialProjectDockerfile
platforms: linux/arm64
pull: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

50 changes: 0 additions & 50 deletions .github/workflows/DiploiInitialProjectBuild.yaml

This file was deleted.

49 changes: 0 additions & 49 deletions .github/workflows/DiploiTemplateBuild.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment && \
RUN ln -s /etc/diploi-git/gitconfig /etc/gitconfig
COPY diploi-credential-helper /usr/local/bin

# Install code server
RUN curl -fsSL https://code-server.dev/install.sh | sh
COPY diploi-vscode-settings.json /usr/local/etc/diploi-vscode-settings.json

# Init and run supervisor
COPY diploi-runonce.sh /usr/local/bin/diploi-runonce.sh
COPY supervisord.conf /etc/supervisord.conf
Expand Down
5 changes: 5 additions & 0 deletions diploi-runonce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ if [ ! "$(ls -A /app)" ]; then

# Configure the SQLTools VSCode extension
# TODO: How to update these if env changes?
mkdir -p /root/.local/share/code-server/User
cp /usr/local/etc/diploi-vscode-settings.json /root/.local/share/code-server/User/settings.json
cat > /app/.vscode/settings.json << EOL
{
"sqltools.connections": [
Expand All @@ -62,6 +64,8 @@ if [ ! "$(ls -A /app)" ]; then
}
EOL



progress "Installing";
npm install;

Expand All @@ -79,6 +83,7 @@ node /app/lib/seedDatabase.js

# Now that everything is initialized, start all services
supervisorctl start www
supervisorctl start code-server

progress "Runonce done";

Expand Down
7 changes: 7 additions & 0 deletions diploi-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ hosts:
identifier: app
urlFormat: '[label].[default-domain]'

editors:
- name: App
identifier: app
service: app
port: 3001
stages:
- development
ssh:
- usernameFormat: '[label]'
contexts: label=app
Expand Down
4 changes: 4 additions & 0 deletions diploi-vscode-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"workbench.colorTheme": "Default Dark+",
"workbench.startupEditor": "none"
}
2 changes: 1 addition & 1 deletion initialProject/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ yarn-error.log*
next-env.d.ts

# VSCode settings
/.vscode/settings.json
/.vscode/settings.json
2 changes: 1 addition & 1 deletion initialProject/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/diploi/nextjs-postgresql-template-arm64
FROM ghcr.io/diploi/nextjs-postgresql-template

# Install application code
WORKDIR /app
Expand Down
10 changes: 10 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ stopasgroup=true
killasgroup=true
stdout_logfile=/var/log/status.log
stderr_logfile=/var/log/status.log

[program:code-server]
directory=/app
command=code-server --app-name Diploi --disable-getting-started-override --disable-workspace-trust --disable-update-check --disable-telemetry --auth none --bind-addr 0.0.0.0:3001 /app
autostart=false
autorestart=true
stopasgroup=true
killasgroup=true
stdout_logfile=/var/log/code-server.log
stderr_logfile=/var/log/code-server.log
2 changes: 2 additions & 0 deletions templates/app-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ spec:
name: app
- port: 3000
name: status
- port: 3001
name: editor
selector:
app: app
1 change: 1 addition & 0 deletions templates/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ spec:
ports:
- containerPort: 80
- containerPort: 3000
- containerPort: 3001
#startupProbe:
# exec:
# command:
Expand Down

0 comments on commit 341a984

Please sign in to comment.