Skip to content

Commit 879a124

Browse files
committed
Quick launch + editor support
1 parent f830dbf commit 879a124

10 files changed

+166
-101
lines changed

.github/workflows/DiploiBuild.yaml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: DiploiBuild
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
INITIAL_PROJECT_IMAGE_NAME: ${{ github.repository }}-initial-project
14+
DEMO_TARGET_REPOSITORY: 'https://x-access-token:${{ secrets.DEMO_REPOSITORY_PAT }}@github.com/diploi/${{ github.repository }}-demo.git'
15+
DEMO_TAG_NAME: '${GITHUB_REF#refs/tags/}'
16+
17+
jobs:
18+
19+
DemoSync:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout source repository
23+
uses: actions/checkout@v2
24+
25+
- name: Sync initialProject folder and push tag
26+
run: |
27+
# Configure git
28+
git config --global user.email "demo-sync@diploi.com"
29+
git config --global user.name "Demo Sync"
30+
31+
# Clone the target repository using HTTPS and PAT for authentication
32+
git clone ${{ env.DEMO_TARGET_REPOSITORY }} temp_repo
33+
cd temp_repo
34+
35+
# Sync the folder
36+
rsync -av --delete --exclude='.git/' ../initialProject/ ./
37+
38+
# Commit and push the changes, if there are any
39+
git add .
40+
git diff --quiet && git diff --staged --quiet || (git commit -m "Commit sync" && git push origin main)
41+
42+
# Tag and push the tag
43+
git tag ${{ env.DEMO_TAG_NAME }}
44+
git push origin --tags
45+
46+
47+
TemplateBuild:
48+
runs-on: ubuntu-latest
49+
permissions:
50+
contents: read
51+
packages: write
52+
53+
steps:
54+
- name: Checkout code
55+
uses: actions/checkout@v3
56+
57+
- name: Docker meta
58+
id: meta
59+
uses: docker/metadata-action@v4
60+
with:
61+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
62+
63+
- name: Set up Docker Buildx
64+
uses: docker/setup-buildx-action@v2
65+
66+
- name: Log in to the GitHub container registry
67+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
68+
with:
69+
registry: ${{ env.REGISTRY }}
70+
username: ${{ github.actor }}
71+
password: ${{ secrets.GITHUB_TOKEN }}
72+
73+
- name: Build and push
74+
uses: docker/build-push-action@v3
75+
with:
76+
context: .
77+
platforms: linux/arm64
78+
pull: true
79+
push: ${{ github.event_name != 'pull_request' }}
80+
tags: ${{ steps.meta.outputs.tags }}
81+
labels: ${{ steps.meta.outputs.labels }}
82+
83+
InitialProjectBuild:
84+
needs: TemplateBuild
85+
runs-on: ubuntu-latest
86+
permissions:
87+
contents: read
88+
packages: write
89+
90+
steps:
91+
- name: Checkout code
92+
uses: actions/checkout@v3
93+
94+
- name: Docker meta
95+
id: meta
96+
uses: docker/metadata-action@v4
97+
with:
98+
images: ${{ env.REGISTRY }}/${{ env.INITIAL_PROJECT_IMAGE_NAME }}
99+
100+
- name: Set up Docker Buildx
101+
uses: docker/setup-buildx-action@v2
102+
103+
- name: Log in to the GitHub container registry
104+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
105+
with:
106+
registry: ${{ env.REGISTRY }}
107+
username: ${{ github.actor }}
108+
password: ${{ secrets.GITHUB_TOKEN }}
109+
110+
- name: Build and push
111+
uses: docker/build-push-action@v3
112+
with:
113+
context: .
114+
file: InitialProjectDockerfile
115+
platforms: linux/arm64
116+
pull: true
117+
push: ${{ github.event_name != 'pull_request' }}
118+
tags: ${{ steps.meta.outputs.tags }}
119+
labels: ${{ steps.meta.outputs.labels }}
120+

.github/workflows/DiploiInitialProjectBuild.yaml

Lines changed: 0 additions & 50 deletions
This file was deleted.

.github/workflows/DiploiTemplateBuild.yaml

Lines changed: 0 additions & 49 deletions
This file was deleted.

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment && \
3131
RUN ln -s /etc/diploi-git/gitconfig /etc/gitconfig
3232
COPY diploi-credential-helper /usr/local/bin
3333

34+
# Install code server
35+
RUN curl -fsSL https://code-server.dev/install.sh | sh
36+
COPY diploi-vscode-settings.json /usr/local/etc/diploi-vscode-settings.json
37+
3438
# Init and run supervisor
3539
COPY diploi-runonce.sh /usr/local/bin/diploi-runonce.sh
3640
COPY supervisord.conf /etc/supervisord.conf

diploi-runonce.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,23 @@ if [ ! "$(ls -A /app)" ]; then
3030

3131
progress "Pulling code";
3232

33-
git init;
33+
git init --initial-branch=main
3434
git config credential.helper '!diploi-credential-helper';
3535
git remote add --fetch origin $REPOSITORY_URL;
36-
git checkout -f $REPOSITORY_BRANCH;
36+
if [ -z "$REPOSITORY_TAG" ]; then
37+
git checkout -f $REPOSITORY_BRANCH;
38+
else
39+
git checkout -f -q $REPOSITORY_TAG;
40+
git checkout -b main
41+
git branch --set-upstream-to=origin/main main
42+
fi
3743
git remote set-url origin "$REPOSITORY_URL";
3844
git config --unset credential.helper;
3945

46+
# Configure VSCode
47+
mkdir -p /root/.local/share/code-server/User
48+
cp /usr/local/etc/diploi-vscode-settings.json /root/.local/share/code-server/User/settings.json
49+
4050
progress "Installing";
4151
npm install;
4252

@@ -50,6 +60,7 @@ env >> /etc/environment
5060

5161
# Now that everything is initialized, start all services
5262
supervisorctl start www
63+
supervisorctl start code-server
5364

5465
progress "Runonce done";
5566

diploi-template.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,21 @@ parameterGroups:
4747
repositories:
4848
- name: app
4949
identifier: app
50+
initialProjectRepositoryUrl: github.com/diploi/astro-template-demo
5051

5152
hosts:
5253
- name: App
5354
identifier: app
5455
urlFormat: '[name].[default-domain]'
5556

57+
editors:
58+
- name: App
59+
identifier: app
60+
service: app
61+
port: 3001
62+
stages:
63+
- development
64+
5665
ssh:
5766
- usernameFormat: 'app'
5867
contexts: label=app

diploi-vscode-settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"workbench.colorTheme": "Default Dark Modern",
3+
"workbench.startupEditor": "none"
4+
}

supervisord.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,14 @@ stopasgroup=true
5252
killasgroup=true
5353
stdout_logfile=/var/log/status.log
5454
stderr_logfile=/var/log/status.log
55+
56+
[program:code-server]
57+
directory=/app
58+
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
59+
autostart=false
60+
autorestart=true
61+
stopasgroup=true
62+
killasgroup=true
63+
stdout_logfile=/var/log/code-server.log
64+
stderr_logfile=/var/log/code-server.log
65+

templates/app-service.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ spec:
88
name: app
99
- port: 3000
1010
name: status
11+
- port: 3001
12+
name: editor
1113
selector:
1214
app: app

templates/app.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ spec:
3939
ports:
4040
- containerPort: 80
4141
- containerPort: 3000
42+
- containerPort: 3001
4243
#startupProbe:
4344
# exec:
4445
# command:
@@ -112,6 +113,8 @@ spec:
112113
value: {{ .Values.repositories.app.url }}
113114
- name: REPOSITORY_BRANCH
114115
value: {{ .Values.repositories.app.branch }}
116+
- name: REPOSITORY_TAG
117+
value: {{ .Values.repositories.app.tag }}
115118
- name: APP_PUBLIC_URL
116119
value: {{ .Values.hosts.app }}
117120
- name: STAGE

0 commit comments

Comments
 (0)