3 minutes
Gitea, Golang, GoReleaser and Drone CI - Part 2
- Gitea, Golang, GoReleaser and Drone CI - Part 1
- Gitea, Golang, GoReleaser and Drone CI - Part 2 <- You are Here
- Gitea, Golang, GoReleaser and Drone CI - Part 3
- Gitea, Golang, GoReleaser and Drone CI - Part 4
In this post, we’ll create our Gitea container, a git repo to hold our code, and a very basic hello world program in Go.
I’m going to assume you already have Docker Desktop1, vscode and Remote - Containers extension installed. If you don’t, go do that now. I also assume some basic knowledge about git and how to use git repository hosting services like Github.
I’ve provided a vscode devcontainer configuration which includes the tools you’ll need for the entire project, so to make things easy I recommend you use that.
Start by cloning my example repository and then checkout 10d412a
, this commit includes only the necessary devcontainer and docker-compose for bringing up Gitea. Finally, open the folder in vscode.
git clone https://github.com/iJebus/go-goreleaser-drone-example.git
cd go-goreleaser-drone-example
git checkout 10d412a
code .
You should be prompted by vscode to reopen in a devcontainer, which you should do. The devcontainer will then build and finally you’ll be ready to go. Time to bring up Gitea.
# use the terminal on the docker host or inside the vscode devcontainer, it's the same one either way
$ docker-compose up -d
Starting gitea ... done
If you followed my preferred method from the previous post and have updated your /etc/hosts
file, you should now access Gitea at http://gitea:3000. You’ll see a lot of configuration which you can ignore, just scroll to the bottom and hit Install Gitea
. There will be a brief loading screen, after which you should click Register
in the top right. I recommend the username gitea
, and later steps will assume this, but all other values can be set however you like.
Create a new project in Gitea. This is the project that’s going to host our Golang project, including the GoReleaser and Drone CI configuration. I’m going bouldering later today so I’ll call mine crimp-city
. Clone this project somewhere in the devcontainer2, as the devcontainer already has the current latest version of Go installed.
$ pwd
/workspaces/go-goreleaser-drone-example
$ git clone http://gitea:3000/gitea/crimp-city.git
Cloning into 'crimp-city'...
warning: You appear to have cloned an empty repository.
Now to create our basic go program.
$ cd crimp-city
$ go mod init crimp-city
go: creating new go.mod: module crimp-city
$ touch main.go
Open main.go
in vscode and fill it with something like the below.
package main
import "fmt"
var version = "dev"
func main() {
fmt.Printf(`
█░█ █▀▀ █░░ █░░ █▀█ █░█░█ █▀█ █▀█ █░░ █▀▄
█▀█ ██▄ █▄▄ █▄▄ █▄█ ▀▄▀▄▀ █▄█ █▀▄ █▄▄ █▄▀ version %s
`, version)
}
Let’s test that works.
$ go run main.go
█░█ █▀▀ █░░ █░░ █▀█ █░█░█ █▀█ █▀█ █░░ █▀▄
█▀█ ██▄ █▄▄ █▄▄ █▄█ ▀▄▀▄▀ █▄█ █▀▄ █▄▄ █▄▀ version dev
Sweet! Let’s commit these back to Gitea and call it a day!
$ git add go.mod main.go
$ git commit -m "initial commit"
[master (root-commit) 9dac672] initial commit
2 files changed, 15 insertions(+)
create mode 100644 go.mod
create mode 100644 main.go
$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 424 bytes | 424.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
remote: . Processing 1 references
remote: Processed 1 references in total
To http://gitea:3000/gitea/crimp-city.git
* [new branch] master -> master
Goovy, see you in the next post where we’ll be implementing GoReleaser.