첫번째 플랫팩 응용프로그램 빌드#
이 튜토리얼은 플랫팩을 간략히 소개한다. 이를 통해 기본 플랫팩 응용프로그램을 생성하고, 설치 및 실행하는 방법을 배운다.
In order to complete this tutorial, you should have followed the setup guide
on flatpak.org. You also need to have installed
flatpak-builder
, which is usually available from the same repository as
the flatpak
package (e.g. use apt
or dnf
). You can also install
it as a flatpak with flatpak install flathub org.flatpak.Builder
.
1. 런타임과 SDK 쌍 설치#
플랫팩은 각 응용프로그램이 런타임을 지정하여 기본적인 의존성을 해결하도록 한다. 각 런타임에는 그와 짝을 이루는 SDK(Software Development Kit)가 존재하는데, 여기에는 실행시간에 필요한 모든 자원 및 헤더파일과 개발도구들이 담겨있다. SDK는 응용프로그램을 빌드할 때 사용된다.
In this tutorial we will use the Freedesktop 23.08 runtime and SDK. To install these, run:
$ flatpak install flathub org.freedesktop.Platform//23.08 org.freedesktop.Sdk//23.08
2. 응용프로그램 생성#
튜토리얼을 통해 생성하는 응용프로그램은 간단한 스크립트이다. 빠른 생성을 위해 다음 내용을 빈 파일에 복사한다:
#!/bin/sh
echo "Hello world, from a sandbox"
Now paste this into an empty file and save it as hello.sh
.
3. manifest 추가#
각 플랫팩은 빌드 시, 응용프로그램에 대한 기본 정보와 빌드 방법을 기술하고 있는 manifest 파일을 사용한다. Hello world 응용을 위해 manifest를 추가하려면 빈 파일에 다음과 같은 내용을 추가한다:
id: org.flatpak.Hello
runtime: org.freedesktop.Platform
runtime-version: '23.08'
sdk: org.freedesktop.Sdk
command: hello.sh
modules:
- name: hello
buildsystem: simple
build-commands:
- install -D hello.sh /app/bin/hello.sh
sources:
- type: file
path: hello.sh
Now save the file alongside hello.sh
and call it
org.flatpak.Hello.yml
.
보다 복잡한 응용프로그램의 경우 manifest는 여러개의 모듈로 구성될 수 있다. 이 때, 일반적으로 마지막에 나열된 모듈이 응용프로그램 자신이고, 그보다 위의 모듈들은 응용프로그램이 의존하는 자원으로서, 런타임에 포함되지 않아 응용프로그램과 함께 묶여 배포된다.
4. 응용프로그램 빌드#
Now that the app has a manifest, flatpak-builder
can be used to build it.
This is done by specifying the manifest file and a target directory:
$ flatpak-builder build-dir org.flatpak.Hello.yml
This command will build each module that is listed in the manifest and install
it to the /app
subdirectory, inside the build-dir
directory.
5. 빌드 테스트#
빌드가 성공적이었는지 확인하려면 다음과 같이 실행 해 본다:
$ flatpak-builder --user --install --force-clean build-dir org.flatpak.Hello.yml
$ flatpak run org.flatpak.Hello
This second time we passed in --force-clean
, which means that the
previously created build-dir
directory was deleted before the new build was
started.
응용프로그램이 성공적으로 빌드되었다!
6. 저장소에 응용프로그램 추가#
If you want to share the application you can put it in a
repository. This is done by passing the --repo
argument to
flatpak-builder
:
$ flatpak-builder --repo=repo --force-clean build-dir org.flatpak.Hello.yml
This does the build again, and at the end exports the result to a local
directory called repo
. Note that flatpak-builder
keeps a cache of
previous builds in the .flatpak-builder
subdirectory, so doing a second
build like this is very fast.
In order for your application to show up in application stores while testing with a local repository, you might have
to run flatpak build-update-repo repo
.
For more information how to publish to application stores see MetaInfo files.
7. 응용프로그램 설치#
이제 막 생성된 저장소를 추가하고 응용프로그램을 설치할 준비가 되었다. 다음 두 명령어를 입력 해 보자:
$ flatpak --user remote-add --no-gpg-verify tutorial-repo repo
$ flatpak --user install tutorial-repo org.flatpak.Hello
첫번째 명령은 위에서 막 생성한 저장소를 추가하는 명령이다. 두번째 명령은 저장소로부터 응용프로그램을 받아 설치하는 명령이다.
Both these commands use the --user
argument, which means that the
repository and the app are added per-user rather than system-wide. This is
useful for testing.
Note that the repository was added with --no-gpg-verify
, since a GPG key
wasn’t specified when the app was built. This is fine for testing, but for
official repositories you should sign them with a private GPG key.
8. 응용프로그램 실행#
이제 남은 작업은 응용프로그램을 실행하는 것 뿐이다. 다음과 같이 실행할 수 있다.
$ flatpak run org.flatpak.Hello
This runs the app, so that it prints ‘Hello world, from a sandbox’.