Skip to content

Commit 672a0cd

Browse files
authored
Fixed init container (#2)
* CI automation * CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * [skip ci] CI automation * CI/CD configured * Added headless mode for automated tests * fixed init container / added storing artifacts in github releases / other minor fixes * release job fix * [skip ci] release job fix * release job fix2 * release job fix3 * release job fix4 * fixed AT
1 parent 3b8496e commit 672a0cd

File tree

14 files changed

+142
-75
lines changed

14 files changed

+142
-75
lines changed

.run/debug-in-docker.run.xml renamed to .github/debug-in-docker.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="debug-in-docker" type="Remote">
3-
<module name="keycloak-user-attribute-authenticator" />
3+
<module name="keycloak-username-password-attribute-authenticator" />
44
<option name="USE_SOCKET_TRANSPORT" value="true" />
55
<option name="SERVER_MODE" value="false" />
66
<option name="SHMEM_ADDRESS" />

.github/workflows/automation_tests.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v2
14+
1415
- name: Set up JDK 11
1516
uses: actions/setup-java@v2
1617
with:
1718
java-version: '11'
1819
distribution: 'adopt'
20+
1921
- name: Build authenticator jar file
2022
run: mvn -B -ntp package
21-
- name: Build test Docker container
22-
run: docker build -f src/main/docker/dev.Dockerfile -t kilmajster/keycloak-with-authenticator:test .
23+
24+
- name: Build test docker container
25+
run: docker-compose build
26+
2327
- name: Run Selenide tests
24-
run: mvn -B -ntp test -P automation-tests
28+
run: mvn -B -ntp test -P automation-tests -D headless=true

.github/workflows/publish.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
name: Publish package to the Maven Central Repository & Docker Hub
2+
23
on:
34
release:
45
types: [created]
6+
57
jobs:
68
release:
79
runs-on: ubuntu-latest
810
steps:
911
- uses: actions/checkout@v2
12+
1013
- name: Set up Maven Central Repository
1114
uses: actions/setup-java@v2
1215
with:
@@ -15,16 +18,21 @@ jobs:
1518
server-id: ossrh
1619
server-username: MAVEN_USERNAME
1720
server-password: MAVEN_PASSWORD
18-
- name: Build project
21+
22+
- name: Build a project
1923
run: mvn -B -ntp package
24+
2025
- name: Get the tag name
2126
run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
27+
2228
- name: Set version from git tag
2329
run: mvn -B -ntp versions:set -DgenerateBackupPoms=false -DnewVersion="$TAG"
24-
- name: Import gpg secret key
30+
31+
- name: Import GPG key
2532
run: |
2633
cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import
2734
gpg --list-secret-keys --keyid-format LONG
35+
2836
- name: Publish maven package
2937
run: |
3038
mvn \
@@ -36,19 +44,33 @@ jobs:
3644
env:
3745
MAVEN_USERNAME: kilmajster
3846
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
47+
48+
- name: Add jar to github release
49+
uses: svenstaro/upload-release-action@v2
50+
with:
51+
repo_token: ${{ secrets.GITHUB_TOKEN }}
52+
file: target/keycloak-username-password-attribute-authenticator-${{ env.TAG }}.jar
53+
asset_name: keycloak-username-password-attribute-authenticator-${{ env.TAG }}.jar
54+
tag: ${{ github.ref }}
55+
3956
- name: Build docker init container
4057
run: |
58+
echo "Building docker image = kilmajster/keycloak-username-password-attribute-authenticator:$TAG" && \
4159
docker build \
60+
--build-arg VERSION="$TAG" \
4261
-f src/main/docker/initContainer.Dockerfile \
4362
-t kilmajster/keycloak-username-password-attribute-authenticator:"$TAG" \
4463
-t kilmajster/keycloak-username-password-attribute-authenticator:latest \
4564
.
65+
4666
- name: Log into Docker Hub
4767
uses: docker/login-action@v1
4868
with:
4969
username: kilmajster
5070
password: ${{ secrets.DOCKER_HUB_TOKEN }}
51-
- name: Push tagged image
71+
72+
- name: Push tagged docker image
5273
run: docker push kilmajster/keycloak-username-password-attribute-authenticator:"$TAG"
53-
- name: Push latest image
74+
75+
- name: Push latest docker image
5476
run: docker push kilmajster/keycloak-username-password-attribute-authenticator:latest

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ hs_err_pid*
2424
/build/
2525
/keycloak-username-password-attribute-authenticator.iml
2626
/.idea/
27-
/target/
27+
/target/

README.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
# keycloak-username-password-attribute-authenticator
1+
# Keycloak username password attribute authenticator
2+
[![CI with Selenide](https://github.com/kilmajster/keycloak-username-password-attribute-authenticator/actions/workflows/automation_tests.yml/badge.svg)](https://github.com/kilmajster/keycloak-username-password-attribute-authenticator/actions/workflows/automation_tests.yml)
3+
![Maven Central](https://img.shields.io/maven-central/v/io.github.kilmajster/keycloak-username-password-attribute-authenticator)
4+
![Docker Image Version (latest by date)](https://img.shields.io/docker/v/kilmajster/keycloak-username-password-attribute-authenticator?label=docker%20hub)
5+
![Docker Pulls](https://img.shields.io/docker/pulls/kilmajster/keycloak-username-password-attribute-authenticator)
6+
![GitHub](https://img.shields.io/github/license/kilmajster/keycloak-username-password-attribute-authenticator)
27

38
## Description
49
Keycloak default login form with user attribute validation.
510

6-
## Using
11+
## How 2 use
712
### using jar
813
### using docker init container
14+
```
15+
kilmajster/keycloak-username-password-attribute-authenticator:latest
16+
```
17+
#### example helm chart snippet
918

1019
## Configuration
1120
### Authenticator config
12-
#### config via Keycloak UI
21+
#### config via Keycloak UI / API
1322
- login_form_user_attribute
1423
- login_form_generate_label
1524
- login_form_attribute_label
@@ -23,16 +32,31 @@ Keycloak default login form with user attribute validation.
2332
#### Using bundled default keycloak theme
2433
#### Extending own theme
2534

26-
## docker
27-
### example in docker-compose
35+
-------------------------------------
36+
### Development
37+
#### build the project
2838
```shell
29-
$ docker-compose up --build --force-recreate
39+
$ mvn package
3040
```
31-
http://localhost:8081/auth/realms/dev-realm/account
32-
41+
#### run with docker-compose
42+
```shell
43+
$ docker-compose up --build
44+
```
45+
http://localhost:8081/auth/realms/dev-realm/account
46+
##### debug in docker with IntelliJ
47+
`.github/debug-in-docker.run.xml`
3348

34-
### init container
49+
#### automation tests
50+
##### build test docker image
51+
```shell
52+
$ docker-compose build
3553
```
36-
kilmajster/keycloak-username-password-attribute-authenticator:latest
54+
##### running tests with chrome
55+
```shell
56+
$ mvn test -P automation-tests
57+
```
58+
##### running tests in docker
59+
```shell
60+
$ mvn test -P automation-tests -D headless=true
3761
```
3862

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
- 8081:8080
1212
- 8787:8787
1313
volumes:
14-
- ./src/main/resources/dev-realm.json:/tmp/dev-realm.json
14+
- ./src/test/resources/dev-realm.json:/tmp/dev-realm.json
1515
environment:
1616
DEBUG: 'true'
1717
DEBUG_PORT: '*:8787'

src/main/docker/dev.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
FROM quay.io/keycloak/keycloak:latest
22

3-
ADD target/keycloak-username-password-attribute-authenticator-*.jar /opt/jboss/keycloak/standalone/deployments
3+
ADD target/keycloak-username-password-attribute-authenticator-SNAPSHOT.jar /opt/jboss/keycloak/standalone/deployments
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
FROM busybox
22

3-
COPY target/keycloak-username-password-attribute-authenticator-*.jar /opt/jboss/keycloak/standalone/deployments/
3+
ARG VERSION
4+
5+
COPY target/keycloak-username-password-attribute-authenticator-${VERSION}.jar /opt/jboss/keycloak/standalone/deployments/

src/main/resources/theme/base-with-attribute/login/login.ftl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@
4141
<#else>
4242
${msg("login_form_attribute_label_default")}
4343
</#if>
44-
</label>
44+
</label>
4545

46-
<input tabindex="3" id="login_form_user_attribute" class="${properties.kcInputClass!}" name="login_form_user_attribute" type="text" autocomplete="off"
47-
aria-invalid="<#if messagesPerField.existsError('username','password')>true</#if>"
46+
<input tabindex="3" id="login_form_user_attribute" class="${properties.kcInputClass!}"
47+
name="login_form_user_attribute" type="text" autocomplete="off"
48+
aria-invalid="<#if messagesPerField.existsError('login_form_user_attribute')>true</#if>"
4849
/>
4950
</div>
5051
<!-- keycloak-user-attribute-authenticator custom code block end -->

src/test/java/io.github.kilmajster.keycloak/UsernamePasswordAttributeFormAT.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package io.github.kilmajster.keycloak;
22

33

4-
import com.codeborne.selenide.WebDriverRunner;
54
import dasniko.testcontainers.keycloak.KeycloakContainer;
65
import io.github.kilmajster.keycloak.base.BaseKeycloakInDockerAT;
7-
import org.junit.After;
8-
import org.junit.Before;
96
import org.junit.Rule;
107
import org.junit.Test;
11-
import org.openqa.selenium.chrome.ChromeOptions;
12-
import org.openqa.selenium.remote.RemoteWebDriver;
13-
import org.testcontainers.containers.BrowserWebDriverContainer;
148
import org.testcontainers.containers.output.Slf4jLogConsumer;
159

1610
import static io.github.kilmajster.keycloak.base.Steps.*;
@@ -25,26 +19,11 @@ public class UsernamePasswordAttributeFormAT extends BaseKeycloakInDockerAT {
2519
.withNetworkAliases(KEYCLOAK_NETWORK_ALIAS)
2620
.withLogConsumer(new Slf4jLogConsumer(log));
2721

28-
@Rule
29-
public BrowserWebDriverContainer chrome = (BrowserWebDriverContainer) new BrowserWebDriverContainer()
30-
.withCapabilities(new ChromeOptions())
31-
.withNetwork(testNetwork)
32-
.withLogConsumer(new Slf4jLogConsumer(log));
33-
34-
@Before
35-
public void setUp() {
36-
RemoteWebDriver driver = chrome.getWebDriver();
37-
WebDriverRunner.setWebDriver(driver);
38-
}
39-
40-
@After
41-
public void tearDown() {
42-
WebDriverRunner.closeWebDriver();
43-
}
44-
4522
@Test
4623
public void shouldLogIntoAccountConsole() {
47-
go_to_keycloak_account_page(KEYCLOAK_TEST_URL);
24+
final String keycloakBaseUrl = getKeycloakBaseUrl(keycloak);
25+
26+
go_to_keycloak_account_page(keycloakBaseUrl);
4827
click_sign_in_button();
4928
verify_login_form_is_displayed_with_user_attribute_label("Test attr");
5029
log_into_account_console();

0 commit comments

Comments
 (0)