Discourse 플러그인 개발 - 4부 - git 설정

이전 튜토리얼: Developing Discourse Plugins - Part 3 - Add custom site settings


이제 플러그인이 점점 더 정교해지고 있으므로, 개발 방식도 더 정교하게 다뤄야 할 때입니다.

플러그인의 버전 관리 도구로 git 사용을 권장합니다. 또한 다른 사람들과 플러그인 코드를 공유하기 위해 github 사용을 추천합니다.

Git 저장소 생성

GitHub 계정을 생성한 후에는 이 URL을 방문하여 새 저장소를 생성하세요. 이름을 아무렇게나 지정할 수 있지만, 일반적으로 discourse-로 시작하는 이름을 사용하는 것이 좋습니다. 저장소가 공개(public) 상태인지 확인하세요. 저의 화면은 다음과 같았습니다:

로컬 작업 폴더 생성

이 시점에서 저는 컴퓨터에 플러그인을 저장할 로컬 디렉터리를 생성합니다. 저는 보통 ~/code에 두지만, 컴퓨터의 원하는 어디에 두어도 됩니다:

mkdir -p ~/code/discourse-plugin-test
cd ~/code/discourse-plugin-test

이제 GitHub의 안내에 따라 README 파일로 저장소를 초기화해 보겠습니다:

echo "# discourse-plugin-test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:eviltrout/discourse-plugin-test.git
git push -u origin main

마지막으로, 1부에서 설명한 대로 플러그인을 위한 plugin.rb 파일을 생성하세요. 이 예제에서는 간단히 더미 파일을 생성했습니다:

plugin.rb

# name: discourse-plugin-test
# about: Shows how to set up Git
# version: 0.0.1
# authors: Robin Ward

심볼릭 링크 생성

저희의 개발자 가이드를 따랐다면, 컴퓨터 어딘가에 discourse의 체크아웃된 복사본이 있을 것입니다. 저는 ~/code/discourse로 체크아웃했지만, 어디에 두었든 상관없이 아래 코드를 그에 맞게 조정하면 여전히 작동합니다:

cd ~/code/discourse/plugins
ln -s ~/code/discourse-plugin-test .

위의 코드는 discourse 코드와 플러그인 폴더 사이에 심볼릭 링크를 생성했습니다. 개발 서버를 재시작하면 플러그인이 정상적으로 작동하는 것을 확인할 수 있습니다!

이 설정의 장점은 플러그인을 GitHub에 커밋하기만 하면 되고, 플러그인이 포함된 discourse 코드베이스에 대해서는 걱정할 필요가 없다는 점입니다. 변경 사항은 플러그인 자체로만 격리됩니다. discourse 코드를 수정해야 하는 경우에도 여전히 수정할 수 있지만, git은 변경 사항을 별도로 추적합니다!

플러그인 코드베이스에는 한 개의 편집기 창을, Discourse 자체에는 다른 한 개의 편집기 창을 사용하는 것을 권장합니다. 두 가지를 서로 다른 것으로 생각하면 더 쉽습니다.


시리즈의 나머지 부분

1부: 플러그인 기초
2부: 플러그인 아웃렛
3부: 사이트 설정
4부: 이 주제
5부: 관리자 인터페이스
6부: 수용 테스트
7부: 플러그인 게시


이 문서는 버전 관리가 적용됩니다 - 변경 사항을 GitHub에서 제안하세요.

23개의 좋아요
  • After many frustrating attempts, found out that apparently ln -s does not work in a Windows environment, or atleast not how it should.
  • ln -s essentially just copy-pasted the plugin folder into the discourse/plugins folder
  • Apparently, in Windows the way to create symbolic links is to use the mklink command in command prompt (run as administrator, and this command does not natively run in Windows PowerShell either).
  • Using the mklink command (with both arguments /d and /h), although the created symbolic link could be seen present in the directory, the plugin was not working with discourse (and also not showing in /admin/plugins).
  • I tried this multiple times with restarting the rails server, deleting the tmp folder, but to no avail.

@eviltrout, any idea what could I be doing wrong?

2개의 좋아요

I assume you are using Vagrant on windows? If you can’t get the symbolic links sent over, I think the only way you can do it is to copy the plugin into discourse/plugins manually and work from there. It should work as long as you are not making changes to the core discourse app at the same time, which confuses git.

When your plugin is ready, you’ll want to copy it to another directory to package it up for git.

1개의 좋아요

Yeah, OK this should be fine too.
Although the OCD side of me, much preferred the comparatively “cleaner” symbolic links method.

Anyway, Thanks.

@AhmadF.Cheema I had similar problems with the symlinking using Vagrant 1.9.8 on Linux, and a completely standard Discourse Vagrant development environment as per the docs.

The problem is simple when you look into it. From the scope of inside the Vagrant VM, the destination of the symlink is not a valid path. Try executing the command ls -al in the plugins directory inside your VM (in a standard install this is at /vagrant/plugins)

vagrant@discourse:/vagrant/plugins$ ls -al
total 36
drwxr-xr-x 1 vagrant vagrant 4096 Oct 22 09:08 ./
drwxr-xr-x 1 vagrant vagrant 4096 Oct 22 09:10 ../
drwxr-xr-x 1 vagrant vagrant 4096 Sep  7 19:51 discourse-details/
drwxrwxr-x 1 vagrant vagrant 4096 Oct 21 13:56 discourse-narrative-bot/
drwxr-xr-x 1 vagrant vagrant 4096 Oct 21 13:56 discourse-nginx-performance-report/
drwxr-xr-x 1 vagrant vagrant 4096 Sep  7 19:51 discourse-plugin-outlet-locations/
drwxrwxr-x 1 vagrant vagrant 4096 Oct 21 13:56 discourse-presence/
lrwxrwxrwx 1 vagrant vagrant   55 Oct 22 09:08 my-basic-plugin -> /home/marcus/code/discourse/my-basic-plugin
drwxr-xr-x 1 vagrant vagrant 4096 Oct 21 13:56 lazyYT/
drwxr-xr-x 1 vagrant vagrant 4096 Oct 21 13:56 poll/

As you can see, the path /home/marcus/code/discourse/my-basic-plugin cannot possibly be accessible from the VM because it doesn’t exist inside the VM!

The solution is to delete the externally created symlink and set up a separate shared folder in Vagrant, by adding a line to your Vagrantfile:

config.vm.synced_folder "/home/marcus/code/my-basic-plugin",  "/my-basic-plugin"

Then restart the Vagrant VM: vagrant halt && vagrant up so that this change is picked up

Now, when you enter your VM via SSH using vagrant ssh you can create a symlink inside the VM:

cd /vagrant/plugins
ln -s /my-basic-plugin .

Now you can develop in a neatly isolated local folder, and have the neat Git workflow that @eviltrout describes, and the symlinking happens inside the VM. Note that outside the VM, the symlink will be broken - but this shouldn’t matter for our purposes.

3개의 좋아요

If you are developing on Linux using our docker based dev is way simpler

4개의 좋아요

Windows symlinks are different from Unix symlinks, thus your confusion. Windows synlinks are very fussy, requiring particular versions of OS to support and sometimes applications must be written to be aware of this. In other words, the stars must line up perfectly for windows symlinks to work.

A hard link (/H) I dont think work with directories. Your /D makes a symlink on a directory, trumping your /H (which is used to create a hard link to a file, not a directory).

Confusing? Welcome to Windows.

There are four types of links in Windows:

  • MKLINK (no flags) – symbolic link to file
  • MKLINK /H – hard link to file
  • MKLINK /D – symbolic link to directory
  • MKLINK /J – junction (i.e. hard link) to directory

What you need is is a junction which is Windows-speak for hard link to a directory.

Do MKLINK /J to your plugins directory and the system will treat it as a subdirectory. In fact it won’t know otherwise. Beware, it is not common to have a Windows directory (folder in Windows-speak) to point to the same place as another directory, so you’ll get confused very easy and forget that both are the same things.

That’s why you’ll need to run the command in Administrator mode, otherwise Windows won’t let you create the directory junction.

4개의 좋아요

Thanks for the info regarding Windows symlinks @schungx - it should be of help to the OP.

The workaround I described should work fine on any platform, since the symlinks happen inside the (Ubuntu) vagrant box

M

Yup, you’re right. If you can avoid it, avoid messing with Windows. Windows is very picky and may choose to die or go wrong at the most unfortunate moment…

Work for me! 2018-4-29

1. I put discourse & my plugin in Desktop

instead of put 1c7-plugin under discourse/plugin

2. and put a “alias” into discourse/plugins folder

alias is a macOS concept,
it’s the same things as ln -s command

3. Discourse correctly load the plugin

(After reboot server with rails s)

4. Now they are separated, use git to manage code is much easier

Thanks!

macOS Docker 환경에서 심볼릭 링크가 작동하지 않습니다. 플러그인은 플러그인 폴더에 직접 복사한 경우에만 작동합니다.