Skip to content

Commit

Permalink
Fix apache#364 pipelines using an old Ubuntu version (apache#365)
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Zanini <[email protected]>
  • Loading branch information
ricardozanini authored and rgdoliveira committed Jan 29, 2024
1 parent 7fe6188 commit db96a11
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 54 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/check-container-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ jobs:
cancel-in-progress: true
timeout-minutes: 120
name: Integration tests (${{ matrix.container-engine }})
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- name: Install packages
run: |
sudo apt-get -y install \
sudo apt-get update &&\
sudo apt-get -y install --no-install-recommends \
libgpgme-dev \
libbtrfs-dev \
libdevmapper-dev
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ jobs:
uses: actions/checkout@v3

# since we now have to download container-builder deps, we need these packages installed before generating our types.
# we should be able to remove this after https://issues.redhat.com/browse/KOGITO-9106
- name: Install packages
run: |
sudo apt-get -y install \
sudo apt-get update &&\
sudo apt-get -y install --no-install-recommends \
btrfs-progs \
libgpgme-dev \
libbtrfs-dev \
Expand Down
2 changes: 1 addition & 1 deletion container-builder/builder/kaniko_integration_test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (suite *KanikoDockerTestSuite) TearDownSuite() {
} else {
suite.LocalRegistry.StopRegistry()
}
purged, err := suite.Docker.PurgeContainer("", common.REGISTRY_IMG)
purged, err := suite.Docker.PurgeContainer("", common.RegistryImg)
klog.V(log.I).InfoS("Purged containers", "containers", purged)
if err != nil {
klog.V(log.E).ErrorS(err, "Purged registry")
Expand Down
19 changes: 12 additions & 7 deletions container-builder/cleaner/docker_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import (
"github.com/apache/incubator-kie-kogito-serverless-operator/container-builder/util/log"
)

const (
testImg = "busybox"
latestTag = "latest"
testImgLocalTag = "localhost:5000/busybox:latest"
)

func TestDockerIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(DockerTestSuite))
}
Expand All @@ -44,22 +50,21 @@ func (suite *DockerTestSuite) TestImagesOperationsOnDockerRegistryForTest() {
repos, err := registryContainer.GetRepositories()
initialSize := len(repos)
assert.Nil(suite.T(), err)

pullErr := suite.Docker.PullImage(common.TEST_IMG + ":" + common.LATEST_TAG)
pullErr := suite.Docker.PullImage(testImg + ":" + latestTag)
if pullErr != nil {
klog.V(log.E).ErrorS(pullErr, "Pull Error")
}
assert.Nil(suite.T(), pullErr, "Pull image failed")
time.Sleep(2 * time.Second) // Needed on CI
assert.True(suite.T(), suite.LocalRegistry.IsImagePresent(common.TEST_IMG), "Test image not found in the registry after the pull")
tagErr := suite.Docker.TagImage(common.TEST_IMG, common.TEST_IMG_LOCAL_TAG)
assert.True(suite.T(), suite.LocalRegistry.IsImagePresent(testImg), "Test image not found in the registry after the pull")
tagErr := suite.Docker.TagImage(testImg, testImgLocalTag)
if tagErr != nil {
klog.V(log.E).ErrorS(tagErr, "Tag Error")
}

assert.Nil(suite.T(), tagErr, "Tag image failed")
time.Sleep(2 * time.Second) // Needed on CI
pushErr := suite.Docker.PushImage(common.TEST_IMG_LOCAL_TAG, common.REGISTRY_CONTAINER_URL_FROM_DOCKER_SOCKET, "", "")
pushErr := suite.Docker.PushImage(testImgLocalTag, common.RegistryContainerUrlFromDockerSocket, "", "")
if pushErr != nil {
klog.V(log.E).ErrorS(pushErr, "Push Error")
}
Expand All @@ -72,8 +77,8 @@ func (suite *DockerTestSuite) TestImagesOperationsOnDockerRegistryForTest() {
assert.NotNil(suite.T(), repos)
assert.True(suite.T(), len(repos) == initialSize+1)

digest, erroDIgest := registryContainer.Connection.ManifestDigest(common.TEST_IMG, common.LATEST_TAG)
digest, erroDIgest := registryContainer.Connection.ManifestDigest(testImg, latestTag)
assert.Nil(suite.T(), erroDIgest)
assert.NotNil(suite.T(), digest)
assert.NotNil(suite.T(), registryContainer.DeleteImage(common.TEST_IMG, common.LATEST_TAG), "Delete Image not allowed")
assert.NotNil(suite.T(), registryContainer.DeleteImage(testImg, latestTag), "Delete Image not allowed")
}
2 changes: 1 addition & 1 deletion container-builder/cleaner/docker_integration_test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (suite *DockerTestSuite) TearDownSuite() {
} else {
suite.LocalRegistry.StopRegistry()
}
purged, err := suite.Docker.PurgeContainer("", common.REGISTRY_IMG)
purged, err := suite.Docker.PurgeContainer("", common.RegistryImg)
if err != nil {
klog.V(log.E).ErrorS(err, "Error during purged container in TearDown Suite.")
}
Expand Down
12 changes: 9 additions & 3 deletions container-builder/cleaner/registry_docker_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import (
"github.com/apache/incubator-kie-kogito-serverless-operator/container-builder/util/log"
)

const (
testImgSecond = "alpine"
testImgSecondTag = "alpine:latest"
testImgSecondLocalTag = "localhost:5000/alpine:latest"
)

func TestRegistryDockerIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(DockerTestSuite))
}
Expand Down Expand Up @@ -65,20 +71,20 @@ func dockerPullTagPushOnRegistryContainer(suite *DockerTestSuite) bool {
dockerSocketConn := suite.Docker.Connection
d := common.Docker{Connection: dockerSocketConn}

err := d.PullImage(common.TEST_IMG_SECOND)
err := d.PullImage(testImgSecond)
time.Sleep(2 * time.Second) // needed on CI
if err != nil {
assert.Fail(suite.T(), "Pull Image Failed", err)
return false
}

err = d.TagImage(common.TEST_IMG_SECOND_TAG, common.TEST_IMG_SECOND_LOCAL_TAG)
err = d.TagImage(testImgSecondTag, testImgSecondLocalTag)
if err != nil {
assert.Fail(suite.T(), "Tag Image Failed", err)
return false
}

err = d.PushImage(common.TEST_IMG_SECOND_LOCAL_TAG, common.REGISTRY_CONTAINER_URL_FROM_DOCKER_SOCKET, "", "")
err = d.PushImage(testImgSecondLocalTag, common.RegistryContainerUrlFromDockerSocket, "", "")
if err != nil {
assert.Fail(suite.T(), "Push Image Failed", err)
return false
Expand Down
22 changes: 7 additions & 15 deletions container-builder/common/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,12 @@ import (
"github.com/apache/incubator-kie-kogito-serverless-operator/container-builder/util/log"
)

const REGISTRY_IMG = "registry"
const REGISTRY_IMG_FULL = "docker.io/library/registry"
const REGISTRY_IMG_FULL_TAG = "docker.io/library/registry:latest"
const REGISTRY_CONTAINER_URL_FROM_DOCKER_SOCKET = "tcp://localhost:5000"
const REGISTRY_CONTAINER_URL = "http://localhost:5000"
const TEST_IMG = "busybox"
const TEST_REGISTRY_REPO = "localhost:5000/"
const TEST_REPO = "docker.io/library/"
const LATEST_TAG = "latest"
const TEST_IMG_TAG = "busybox:latest"
const TEST_IMG_SECOND = "alpine"
const TEST_IMG_SECOND_TAG = "alpine:latest"
const TEST_IMG_SECOND_LOCAL_TAG = "localhost:5000/alpine:latest"
const TEST_IMG_LOCAL_TAG = "localhost:5000/busybox:latest"
const (
RegistryContainerUrlFromDockerSocket = "tcp://localhost:5000"
RegistryImg = "registry"
registryImgFullTag = "docker.io/library/registry:latest"
registryContainerUrl = "http://localhost:5000"
)

type Registry interface {
StartRegistry()
Expand Down Expand Up @@ -121,7 +113,7 @@ func (r *RegistryContainer) url(pathTemplate string, args ...interface{}) string
}

func GetRegistryContainer() (RegistryContainer, error) {
registryContainerConnection, err := GetRegistryConnection(REGISTRY_CONTAINER_URL, "", "")
registryContainerConnection, err := GetRegistryConnection(registryContainerUrl, "", "")
if err != nil {
klog.V(log.E).ErrorS(err, "Can't connect to the RegistryContainer")
return RegistryContainer{}, err
Expand Down
31 changes: 8 additions & 23 deletions container-builder/common/registry_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,6 @@ func GetDockerConnection() (*client.Client, error) {
return cli, nil
}

func GetCustomDockerConnectionWithIP(ip string) (*client.Client, error) {
return client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation(), client.WithHost(ip))
}

func GetCustomRegistry() (DockerLocalRegistry, *client.Client, error) {
connectionLocal, err := GetCustomDockerConnectionWithIP(REGISTRY_CONTAINER_URL_FROM_DOCKER_SOCKET)
if err != nil {
klog.V(log.E).ErrorS(err, "error during Get Custom Registry")
return DockerLocalRegistry{}, nil, err
}

d := DockerLocalRegistry{Connection: connectionLocal}
return d, connectionLocal, nil
}

func (d DockerLocalRegistry) getConnection() (*client.Client, error) {
connectionLocal := d.Connection
if connectionLocal == nil {
Expand Down Expand Up @@ -86,7 +71,7 @@ func (d DockerLocalRegistry) StartRegistry() string {

if !d.IsRegistryImagePresent() {
klog.V(log.I).InfoS("Registry Image Pull")
_, err := d.Connection.ImagePull(ctx, REGISTRY_IMG, types.ImagePullOptions{})
_, err := d.Connection.ImagePull(ctx, RegistryImg, types.ImagePullOptions{})
if err != nil {
fmt.Println(err)
return ""
Expand All @@ -97,15 +82,15 @@ func (d DockerLocalRegistry) StartRegistry() string {

klog.V(log.I).InfoS("Registry Container Create")
resp, err := d.Connection.ContainerCreate(ctx, &container.Config{
Image: REGISTRY_IMG,
Image: RegistryImg,
ExposedPorts: nat.PortSet{"5000": struct{}{}},
},
&container.HostConfig{
PortBindings: map[nat.Port][]nat.PortBinding{nat.Port("5000"): {{HostIP: "127.0.0.1", HostPort: "5000"}}},
},
nil,
nil,
REGISTRY_IMG)
RegistryImg)

if err != nil {
klog.V(log.E).ErrorS(err, "error during Registry Container Create")
Expand Down Expand Up @@ -160,7 +145,7 @@ func (d DockerLocalRegistry) GetRegistryRunningID() string {
}

for _, container := range containers {
if container.Image == REGISTRY_IMG {
if container.Image == RegistryImg {
return container.ID
}
}
Expand All @@ -174,7 +159,7 @@ func (d DockerLocalRegistry) IsRegistryImagePresent() bool {
return false
}
for _, imagex := range imageList {
if (len(imagex.RepoTags) > 0 && imagex.RepoTags[0] == REGISTRY_IMG) || (imagex.RepoDigests != nil && strings.HasPrefix(imagex.RepoDigests[0], REGISTRY_IMG)) {
if (len(imagex.RepoTags) > 0 && imagex.RepoTags[0] == RegistryImg) || (len(imagex.RepoDigests) > 0 && strings.HasPrefix(imagex.RepoDigests[0], RegistryImg)) {
return true
}
}
Expand Down Expand Up @@ -210,20 +195,20 @@ func SetupDockerSocket() (DockerLocalRegistry, string, Docker) {
if err != nil {
klog.V(log.E).ErrorS(err, "error during SetupDockerSocket")
}
_, err = dockerSock.PurgeContainer("", REGISTRY_IMG)
_, err = dockerSock.PurgeContainer("", RegistryImg)
if err != nil {
klog.V(log.E).ErrorS(err, "error during SetupDockerSocket")
}

d := DockerLocalRegistry{Connection: dockerSocketConn}
klog.V(log.I).InfoS("Check if registry image is present", "isPresent", d.IsRegistryImagePresent())
if !d.IsRegistryImagePresent() {
dockerSock.PullImage(REGISTRY_IMG_FULL_TAG)
dockerSock.PullImage(registryImgFullTag)
}
registryID := d.GetRegistryRunningID()
if len(registryID) == 0 {
registryID = d.StartRegistry()
klog.V(log.E).ErrorS(err, "Registry started")
klog.V(log.I).InfoS("Registry started")
} else {
klog.V(log.I).InfoS("Registry already up and running", "ID", registryID)
}
Expand Down

0 comments on commit db96a11

Please sign in to comment.