From 79df3eaf0bad9e9a5cdd00f91917bb505238afd9 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Sat, 24 Aug 2024 03:09:55 +0100 Subject: [PATCH] Build and push docker image --- .github/workflows/ci.yaml | 40 ++++++++++++++++++++++++++++++++++++++- Dockerfile | 20 ++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3f38670..80220f0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,6 +18,45 @@ jobs: version: 9 - run: pnpm install - run: pnpm run build-keycloak-theme + + + docker_build: + name: Build Docker image + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' }} + needs: test + env: + KEYCLOAK_VERSION: 25.0.4 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ github.token }} + + # Build and push the container to the GitHub Container + # Repository. The container will be tagged as "latest" + # and with the short SHA of the commit. + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: ${{ github.ref == 'refs/heads/main' }} + cache-from: type=registry,ref=ghcr.io/owl-corp/keycloak:latest + cache-to: type=inline + tags: | + ghcr.io/owl-corp/keycloak:latest + ghcr.io/owl-corp/keycloak:${{ env.KEYCLOAK_VERSION }} + build-args: | + KEYCLOAK_VERSION=${{ env.KEYCLOAK_VERSION }} check_if_version_upgraded: name: Check if version upgrade @@ -35,7 +74,6 @@ jobs: with: action_name: is_package_json_version_upgraded branch: ${{ github.head_ref || github.ref }} - create_github_release: runs-on: ubuntu-latest needs: check_if_version_upgraded diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..04fbbf4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM node:20 as keycloakify_jar_builder +RUN apt-get update && \ + apt-get install -y openjdk-17-jdk && \ + apt-get install -y maven; +COPY ./keycloakify-starter/package.json ./keycloakify-starter/pnpm-lock.yaml /opt/app/ +WORKDIR /opt/app +RUN pnpm install +COPY ./keycloakify-starter/ /opt/app/ +RUN pnpm run build + +ARG KEYCLOAK_VERSION=25.0.4 +FROM quay.io/keycloak/keycloak:${KEYCLOAK_VERSION} as builder +WORKDIR /opt/keycloak +COPY --from=keycloakify_jar_builder /opt/app/dist_keycloak/keycloak-theme-for-kc-22-and-above.jar /opt/keycloak/providers/ +RUN /opt/keycloak/bin/kc.sh build + +FROM quay.io/keycloak/keycloak:${KEYCLOAK_VERSION} +COPY --from=builder /opt/keycloak/ /opt/keycloak/ + +ENTRYPOINT ["/opt/keycloak/bin/kc.sh", "start", "--optimized"]