Skip to content

Commit 67a63ab

Browse files
authored
feat: add build tools docker images for github actions (#6)
1 parent fc0458e commit 67a63ab

File tree

8 files changed

+159
-171
lines changed

8 files changed

+159
-171
lines changed

.github/workflows/build-tools.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: build-tools-CI
2+
on:
3+
push:
4+
branches:
5+
- develop
6+
paths:
7+
- 'tools/**'
8+
9+
jobs:
10+
build-tools-ci:
11+
name: build
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out code
15+
uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 1
18+
19+
- name: Login to GitHub Container Registry
20+
uses: docker/login-action@v1
21+
with:
22+
username: ${{ github.repository_owner }}
23+
password: ${{ secrets.GITHUB_TOKEN }}
24+
registry: ghcr.io
25+
26+
- name: Build and publish Tools image
27+
run: make publish-build-tools
28+
29+
- name: Build and publish Git Server tool image
30+
run: make publish-git-server-tool

.github/workflows/pull_request_tests.yml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,24 @@ jobs:
2121
tests:
2222
name: Tests
2323
runs-on: ubuntu-latest
24+
container:
25+
image: ghcr.io/docplanner/helm-repo-updater/build-tools:develop
26+
# TODO: Remind to delete this part when we make public the repository
27+
credentials:
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.CR_PAT }}
30+
services:
31+
git-server:
32+
image: ghcr.io/docplanner/helm-repo-updater/git-repo-server:develop
33+
# TODO: Remind to delete this part when we make public the repository
34+
credentials:
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.CR_PAT }}
2437
steps:
2538
- uses: actions/checkout@v2
2639

27-
- uses: actions/setup-go@v2
28-
with:
29-
go-version: 1.17
30-
31-
- name: Launch git-server
32-
run: make launch-test-deps
33-
- name: Configure test known_hosts
34-
run: |
35-
chmod 600 test-git-server/private_keys/helm-repo-updater-test
36-
mkdir -p ~/.ssh/
37-
ssh-keyscan -p 2222 localhost >> ~/.ssh/known_hosts
38-
3940
- run: make build
4041

41-
- run: make test
42+
- run: make test-coverage
43+
env:
44+
isCI: true

Makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ GO_OUTPUT = $(CURDIR)/bin/$(APP_NAME)
55
APP_NAME ?= helm-repo-updater
66
GO_TEST_DEFAULT_ARG = -v ./internal/...
77

8+
IMAGE_REGISTRY ?= ghcr.io
9+
IMAGE_REPO ?= docplanner
10+
11+
IMAGE_BUILD_TOOLS = $(IMAGE_REGISTRY)/$(IMAGE_REPO)/helm-repo-updater/build-tools:develop
12+
IMAGE_GIT_REPO_SERVER_TOOL = $(IMAGE_REGISTRY)/$(IMAGE_REPO)/helm-repo-updater/git-repo-server:develop
13+
814
.PHONY: build
915
build: clean
1016
@echo "`date +'%d.%m.%Y %H:%M:%S'` Building $(GO_INPUT)"
@@ -18,7 +24,9 @@ clean:
1824

1925
.PHONY: launch-test-deps
2026
launch-test-deps:
27+
ifndef isCI
2128
docker-compose -f test-git-server/docker-compose.yaml up -d
29+
endif
2230

2331
.PHONY: clean-test-deps
2432
clean-test-deps:
@@ -29,7 +37,7 @@ clean-test-deps:
2937
test: test-unit
3038

3139
.PHONY: test-benchmark
32-
test-benchmark: launch-test-deps
40+
test-benchmark: isCIlaunch-test-deps
3341
$(GO) test ${GO_TEST_DEFAULT_ARG} -cpu 1,2,4,8 -benchmem -bench .
3442

3543
.PHONY: test-unit
@@ -51,6 +59,16 @@ golangci-lint: $(GOBIN_TOOL)
5159
gofumpt: $(GOBIN_TOOL)
5260
GOOS=linux $(GOBIN_TOOL) -run mvdan.cc/gofumpt -l -w .
5361

62+
.PHONY: publish-build-tools
63+
publish-build-tools: ## Publish build-tools image
64+
docker build -f tools/build-tools.Dockerfile -t $(IMAGE_BUILD_TOOLS) .
65+
docker push $(IMAGE_BUILD_TOOLS)
66+
67+
.PHONY: publish-git-server-tool
68+
publish-git-server-tool: ## Publish build-tools image
69+
docker build -f test-git-server/git-server/Dockerfile -t $(IMAGE_GIT_REPO_SERVER_TOOL) .
70+
docker push $(IMAGE_GIT_REPO_SERVER_TOOL)
71+
5472
$(GOBIN_TOOL):
5573
go get github.com/myitcv/gobin
5674
go install github.com/myitcv/gobin

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/spf13/viper v1.10.0
1212
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473
1313
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
14-
gotest.tools v2.2.0+incompatible
1514
)
1615

1716
require (

internal/app/updater/commit_test.go

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,19 @@ import (
1414

1515
const validGitCredentialsEmail = "[email protected]"
1616
const validGitCredentialsUsername = "test-user"
17-
const validGitRepoHost = "ssh://git@localhost:2222"
17+
18+
// TODO: Remove after CI tests docker layer name
19+
const SSHRepoPrefix = "ssh://git@"
20+
const SSHRepoLocalHostname = SSHRepoPrefix + "localhost:2222"
21+
const SSHRepoCIHostname = SSHRepoPrefix + "git-server"
1822
const validGitRepoRoute = "/git-server/repos/test-repo.git"
19-
const validGitRepoURL = validGitRepoHost + validGitRepoRoute
2023
const invalidGitRepoRoute = "/git-server/repos/test-r"
21-
const invalidGitRepoURL = validGitRepoHost + invalidGitRepoRoute
2224
const validSSHPrivKeyRelativeRoute = "/test-git-server/private_keys/helm-repo-updater-test"
2325
const validGitRepoBranch = "develop"
2426
const invalidGitRepoBranch = "developp"
2527
const validHelmAppName = "example-app"
2628
const validHelmAppFileToChange = validHelmAppName + "/values.yaml"
27-
28-
func loadSSHKeyPath(sshPrivKeyPath string) (string, error) {
29-
dat, err := os.ReadFile(sshPrivKeyPath)
30-
if err != nil {
31-
return "", err
32-
}
33-
34-
return string(dat), nil
35-
}
29+
const ciDiscoveryEnvironment = "isCI"
3630

3731
func TestUpdateApplicationDryRunNoChanges(t *testing.T) {
3832

@@ -52,6 +46,8 @@ func TestUpdateApplicationDryRunNoChanges(t *testing.T) {
5246
SSHPrivKey: sshPrivKeyData,
5347
}
5448

49+
validGitRepoURL := getSSHRepoHostnameAndPort() + validGitRepoRoute
50+
5551
gConf := git.Conf{
5652
RepoURL: validGitRepoURL,
5753
Branch: validGitRepoBranch,
@@ -106,6 +102,8 @@ func TestUpdateApplicationDryRun(t *testing.T) {
106102
SSHPrivKey: sshPrivKeyData,
107103
}
108104

105+
validGitRepoURL := getSSHRepoHostnameAndPort() + validGitRepoRoute
106+
109107
gConf := git.Conf{
110108
RepoURL: validGitRepoURL,
111109
Branch: validGitRepoBranch,
@@ -211,6 +209,8 @@ func TestUpdateApplicationDryRunInvalidGitRepo(t *testing.T) {
211209
SSHPrivKey: sshPrivKeyData,
212210
}
213211

212+
invalidGitRepoURL := getSSHRepoHostnameAndPort() + invalidGitRepoRoute
213+
214214
gConf := git.Conf{
215215
RepoURL: invalidGitRepoURL,
216216
Branch: validGitRepoBranch,
@@ -261,6 +261,8 @@ func TestUpdateApplicationDryRunInvalidGitBranch(t *testing.T) {
261261
SSHPrivKey: sshPrivKeyData,
262262
}
263263

264+
validGitRepoURL := getSSHRepoHostnameAndPort() + validGitRepoRoute
265+
264266
gConf := git.Conf{
265267
RepoURL: validGitRepoURL,
266268
Branch: invalidGitRepoBranch,
@@ -312,6 +314,8 @@ func TestUpdateApplicationDryRuNoBranch(t *testing.T) {
312314
SSHPrivKey: sshPrivKeyData,
313315
}
314316

317+
validGitRepoURL := getSSHRepoHostnameAndPort() + validGitRepoRoute
318+
315319
gConf := git.Conf{
316320
RepoURL: validGitRepoURL,
317321
Branch: "",
@@ -368,6 +372,8 @@ func TestUpdateApplicationDryRunWithGitMessage(t *testing.T) {
368372
SSHPrivKey: sshPrivKeyData,
369373
}
370374

375+
validGitRepoURL := getSSHRepoHostnameAndPort() + validGitRepoRoute
376+
371377
gConf := git.Conf{
372378
RepoURL: validGitRepoURL,
373379
Branch: validGitRepoBranch,
@@ -423,6 +429,8 @@ func TestUpdateApplicationDryRunInvalidKey(t *testing.T) {
423429
SSHPrivKey: sshPrivKeyData,
424430
}
425431

432+
validGitRepoURL := getSSHRepoHostnameAndPort() + validGitRepoRoute
433+
426434
gConf := git.Conf{
427435
RepoURL: validGitRepoURL,
428436
Branch: validGitRepoBranch,
@@ -487,6 +495,8 @@ func TestUpdateApplication(t *testing.T) {
487495
SSHPrivKey: sshPrivKeyData,
488496
}
489497

498+
validGitRepoURL := getSSHRepoHostnameAndPort() + validGitRepoRoute
499+
490500
gConf := git.Conf{
491501
RepoURL: validGitRepoURL,
492502
Branch: validGitRepoBranch,
@@ -520,3 +530,20 @@ func TestUpdateApplication(t *testing.T) {
520530
}
521531
assert.DeepEqual(t, *apps, changeEntries)
522532
}
533+
534+
func getSSHRepoHostnameAndPort() string {
535+
_, isCI := os.LookupEnv(ciDiscoveryEnvironment)
536+
if !isCI {
537+
return SSHRepoLocalHostname
538+
}
539+
return SSHRepoCIHostname
540+
}
541+
542+
func loadSSHKeyPath(sshPrivKeyPath string) (string, error) {
543+
dat, err := os.ReadFile(sshPrivKeyPath)
544+
if err != nil {
545+
return "", err
546+
}
547+
548+
return string(dat), nil
549+
}

test-git-server/git-server/Dockerfile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@ FROM alpine:3.15.0
22

33
LABEL maintainer="Docplanner <[email protected]>"
44

5-
RUN whoami
6-
75
RUN apk add --no-cache openssh git
86

9-
# Key generation on the server
10-
RUN ssh-keygen -A
11-
127
WORKDIR /git-server/
138

149
# -D flag avoids password generation
@@ -18,18 +13,29 @@ RUN mkdir /git-server/keys \
1813
&& echo git:12345 | chpasswd \
1914
&& mkdir /home/git/.ssh
2015

16+
17+
# Create repos folder
18+
RUN mkdir /git-server/repos/
19+
2120
# This is a login shell for SSH accounts to provide restricted Git access.
2221
# It permits execution only of server-side Git commands implementing the
2322
# pull/push functionality, plus custom commands present in a subdirectory
2423
# named git-shell-commands in the user’s home directory.
2524
# More info: https://git-scm.com/docs/git-shell
26-
COPY git-server/git-shell-commands /home/git/git-shell-commands
25+
COPY test-git-server/git-server/git-shell-commands /home/git/git-shell-commands
2726
RUN chmod -R +x /home/git/git-shell-commands
2827

2928
# sshd_config file is edited for enable access key and disable access password
30-
COPY git-server/sshd_config /etc/ssh/sshd_config
31-
COPY git-server/create_repo.sh create_repo.sh
32-
COPY git-server/start.sh start.sh
29+
COPY test-git-server/git-server/sshd_config /etc/ssh/sshd_config
30+
COPY test-git-server/git-server/create_repo.sh create_repo.sh
31+
COPY test-git-server/git-server/start.sh start.sh
32+
33+
# copy predefined ssh public key
34+
COPY test-git-server/repo_keys/id_rsa.pub /git-server/keys/
35+
36+
# copy predefined ssh private key
37+
COPY test-git-server/private_keys/helm-repo-updater-test /etc/ssh
38+
RUN chmod 600 /etc/ssh/helm-repo-updater-test
3339

3440
EXPOSE 22
3541

0 commit comments

Comments
 (0)