LoginSignup
0
0

More than 1 year has passed since last update.

ラズパイにgitlab runnerをインストールした話

Posted at

前回、ラズパイ4にgitlabをインストールしました。
次はCIを行える環境を構築していきたいと思います。

関連記事

   リンク
gitlabインストール ラズパイにgitlab-eeをインストールした話

開発環境

   バージョン
筐体 rasberry Pi4 8GB
OS Ubuntu Server 22.10
gitlab gitlab-ee 15.6.2-ee
gitlab-runner 追加 15.7.1

今回のお題

1.gitlab-runnerのインストール
2.dockerのインストール
3.動作検証

を行っていきます。

1.gitlab-runnerのインストール

Gitlabの「Admin Area」→「Runners」→「Register an Instance runner」→「Show runner installation and registration instructions」の順でクリックし、以下の画面を表示してください。

image.png
※「Download and install binary」の項目に記載されている順にインストールを行ってください。

2.dockerのインストール

gitlab runnersは、裏で、dockerを使って、指定された作業を行っているようです。
正確には、この後の設定で、dockerを選択することで、そうなりますが、今回は、その辺の詳細は省きます。(まだ勉強できておらず、理解できてないだけですw)

以下のコマンドからdockerの公式GPG鍵を取得します。

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

以下のコマンドを実行し、dockerをダウンロードします。

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Docker Engineのインストールを行います。

$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

以下の内容が表示されたら、正常にインストールされたことになります。

$ No VM guests are running outdated hypervisor (qemu) binaries on this host.

3.動作検証

では、実際に動作検証を行っていきます。
利用したコードは、golangでHelloworld!を表示させるだけの簡単なコードです。
そのコードに、静的解析とビルド、UnitTESTを行うようにしてみます。ymlファイルは以下です。

.gitlab-ci.yml
image: golang:latest

stages:
  - lint
  - build
  - unittest

# 静的解析を実施
go_staticcheck:
   stage: lint
   image: golang:latest
   before_script:
     - go install honnef.co/go/tools/cmd/staticcheck@latest
   script:
     - go vet src/main.go
    

# goのビルドを実施
go_build:
  stage: build
  image: golang:latest
  script: go build src/main.go

# UnitTEST実行
go_unittest:
  stage: unittest
  image: golang:latest
  script: go test -v -cover src/main_test.go src/main.go

これをgitlab上にコミットしてみると、以下の様に実行され、無事passedとなりました。
image.png

今回は以上となります。

終わりに

今回は、説明が少し雑になってしまいました。読んでもらったのにすみません。
次回はもう少し、分かりやすく書くようにします。

参考にしたサイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0