Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLING-10229: DockerHub build - using hooks to build and push #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# -----------------------------------------------------------------------------

# intentionally empty
# DockerHub automatic build needs this file to start
34 changes: 34 additions & 0 deletions hooks/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# -----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# -----------------------------------------------------------------------------

# we are on ubuntu xenial (16.4) java-11 is hard to install so we tage java 8

apt-get update -y
apt-get install default-jdk maven -y
java -version
mvn -version
mvn clean package -P container
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this would be a good place to validate that:

  • we don't build a snapshot version
  • the base image name is the one we expect from the pom ( compare with ${IMAGE_NAME} )



echo "start docker build"
docker run -i --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn clean package -P container
echo "end docker build"

# next hook is hook/push
49 changes: 49 additions & 0 deletions hooks/push
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
# -----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# -----------------------------------------------------------------------------

# tags the maven-generated image with the Docker-Hub estimated image-name:latest and additional tags

# name of the image, given by pom.xml
BASE_IMAGE_NAME="sling/feature-launcher"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use ${IMAGE_NAME} instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but then the build will only work on the original apache/sling-org-apache-sling-feature-launcher.

if you want to fort it an run together with your docherhub account the build will fail


# latest tag
docker tag $BASE_IMAGE_NAME $DOCKER_REPO:latest
docker push $DOCKER_REPO:latest

# additional tag with the SHA1 hash of the commit.
docker tag $BASE_IMAGE_NAME $DOCKER_REPO:$SOURCE_COMMIT
docker push $DOCKER_REPO:$SOURCE_COMMIT

# additional tag with project version,
PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? I think we could use ${DOCKER_TAG} instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we only build on tag thennthia should be enough

docker tag $BASE_IMAGE_NAME $DOCKER_REPO:$PROJECT_VERSION
docker push $DOCKER_REPO:$PROJECT_VERSION

# additional tag with snapshot or stable
SNAPSHOT_REGEX="^(.*)-SNAPSHOT"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No snapshots please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

if [[ $PROJECT_VERSION =~ $SNAPSHOT_REGEX ]];
then
docker tag $BASE_IMAGE_NAME $DOCKER_REPO:snapshot
docker push $DOCKER_REPO:snapshot
else
docker tag $BASE_IMAGE_NAME $DOCKER_REPO:stable
docker push $DOCKER_REPO:stable
fi

6 changes: 1 addition & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,8 @@
<configuration>
<images>
<image>
<name>apache/sling-feature-launcher:${project.version}</name>
<name>sling/feature-launcher</name>
<build>
<tags>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we keep this for simpler local builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

<tag>latest</tag>
<tag>${project.version}</tag>
</tags>
<dockerFileDir>.</dockerFileDir>
<assembly>
<descriptorRef>artifact</descriptorRef>
Expand Down
63 changes: 51 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,25 @@ The following command line options are supported:
```
$ rm -rf launcher && java -jar org.apache.sling.feature.launcher.jar -h
usage: launcher
-C <arg> Set artifact clash override
-CC <arg> Set config class override
-c <arg> Set cache dir
-D <arg> Set framework properties
-f <arg> Set feature files (relative and absolute file path or URL including classloader resources)
-p <arg> Set home dir
-u <arg> Set repository url
-V <arg> Set variable value
-ec <arg> Set Extension Configuration (format: extensionName:key1=val1,key2=val2)
-fv <arg> Set Felix Framework version
-fa <arg> Set Framework Artifact (overrides felix framework version)
-v Verbose
-C,--artifact-clash <arg> Set artifact clash override
-c,--cache_dir <arg> Set cache dir
-CC,--config-clash <arg> Set config clash override
-cenv print additional help information
for container env vars.
-D,--framework-properties <arg> Set framework properties
-ec,--extension_configuration <arg> Provide extension configuration,
format:
extensionName:key1=val1,key2=val2
-f,--feature-files <arg> Set feature files
-fa,--osgi-framework-artifact <arg> Set OSGi framework artifact
(overrides Apache Felix framework
version)
-fv,--felix-framework-version <arg> Set Apache Felix framework version
(default 7.0.0)
-p,--home_dir <arg> Set home dir
-u,--repository-urls <arg> Set repository urls
-V,--variable-values <arg> Set variable values
-v,--verbose <arg> Verbose
```

**Note**: if feature files are provided as a Classloader Resource like in an
Expand All @@ -48,4 +55,36 @@ String[] arguments = new String[] {
org.apache.sling.feature.launcher.impl.Main.main(arguments);
```

# Container

The container-image `apache/sling-org-apache-sling-feature-launcher:latest` is avaiable on DockerHub.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the new name.

Copy link
Contributor Author

@stbischof stbischof Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that the new name? i am a bit confused. which name do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant sling/feature-launcher


Available tags:
- **latest** - latest build, could be a `snapshot` **or** `release` version.
- **snapshot** - latest build of a `*-SNAPSHOT` version.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No snapshots please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

- **stable** - latest build of a **release** version.
- **(version)** - latest build of a fixed version, could be a `snapshot - (1.1.9-SNAPSHOT)` **or** `release - (1.1.9)` version.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No snapshots please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you be more explicit.

Will we do this only on creating a git tag?
This should be then tagged as:
-latest
-tagname

  • git hash ?

No snapshot!
No stable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For more context - the ASF release policy says that we only publish releases, not CI artifacts. So for DockerHub, which is a public repository, we should only publish for git tags. A separate discussion is to maybe generate them manually, since after a tag we have a release vote, and only them the publication should happen.

So we should have:

  • version - e.g. 1.0.20
  • latest

I don't think git hash is useful so I would not use that.

- **(sha1)** - uses SHA1 hash of the git commit as tag


If you are running sling-feature-launcher as an container please use env vars.
```
$docker run -it --rm --env FEATURE_FILES=https://path.to/feature-model.json apache/sling-org-apache-sling-feature-launcher:latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the new name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that the new name? i am a bit confused. which name do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant sling/feature-launcher


cli-arg - container ENV variable
-------------------------------------
-C - ARTIFACT_CLASH
-CC - CONFIG_CLASH
-c - CACHE_DIR
-D - FRAMEWORK_PROPERTIES
-f - FEATURE_FILES
-p - HOME_DIR
-u - REPOSITORY_URLS
-V - VARIABLE_VALUES
-ec - EXTENSION_CONFIGURATION
-fv - FELIX_FRAMEWORK_VERSION
-fa - OSGI_FRAMEWORK_ARTIFACT
-v - VERBOSE
```

For further documentation see: https://github.com/apache/sling-org-apache-sling-feature/blob/master/readme.md