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

Add Dockerfile and docker build workflow #2

Open
wants to merge 3 commits into
base: main
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
62 changes: 62 additions & 0 deletions .github/workflows/build-and-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: docker-build-and-push

on:
push:
branches:
- 'main'
pull_request:
types:
- closed

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
if: |
github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true ||
github.event_name == 'push' && github.ref == 'refs/heads/main'

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Set short SHA
id: sha
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Checkout repository
uses: actions/checkout@v4

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags:
type=raw,value=latest,enable=true

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:18 as keycloakify_jar_builder
RUN apt-get update && \
apt-get install -y openjdk-17-jdk && \
apt-get install -y maven;
COPY ./package.json ./yarn.lock /opt/app/
WORKDIR /opt/app
RUN yarn install --frozen-lockfile
COPY . /opt/app/
RUN yarn build-keycloak-theme

FROM docker.io/bitnami/keycloak:24.0.5-debian-12-r0 as builder
WORKDIR /opt/bitnami/keycloak
COPY --from=keycloakify_jar_builder /opt/app/dist_keycloak/keycloak-theme-for-kc-25-and-above.jar /opt/bitnami/keycloak/providers/
RUN /opt/bitnami/keycloak/bin/kc.sh build

FROM docker.io/bitnami/keycloak:24.0.5-debian-12-r0
COPY --from=builder /opt/bitnami/keycloak /opt/bitnami/keycloak
ENV KC_HOSTNAME=localhost
ENTRYPOINT ["/opt/bitnami/keycloak/bin/kc.sh", "start-dev"]