Updates for Zammad 6

This commit is contained in:
Darren Clarke 2023-07-11 10:05:52 +00:00 committed by GitHub
parent 60b82f6fb4
commit 73fdb6e5d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 101 additions and 23 deletions

View file

@ -15,12 +15,8 @@ export const ZammadWrapper: FC<ZammadWrapperProps> = ({
hideSidebar = true, hideSidebar = true,
}) => { }) => {
const router = useRouter(); const router = useRouter();
const [display, setDisplay] = useState("inherit"); const [display, setDisplay] = useState("none");
//const { const url = `/proxy/zammad${path}`;
// publicRuntimeConfig: { linkURL },
// } = getConfig();
const linkURL = "http://localhost:3000";
const url = `${linkURL}/proxy/zammad${path}`;
console.log({ url }); console.log({ url });
return ( return (
@ -34,8 +30,6 @@ export const ZammadWrapper: FC<ZammadWrapperProps> = ({
styles={{ display }} styles={{ display }}
onLoad={() => { onLoad={() => {
const linkElement = document.querySelector("iframe"); const linkElement = document.querySelector("iframe");
// const baseElement = linkElement.contentDocument.createElement("base");
// baseElement.href = `${linkURL}/proxy/zammad`;
if ( if (
linkElement.contentDocument && linkElement.contentDocument &&
linkElement.contentDocument?.querySelector && linkElement.contentDocument?.querySelector &&

View file

@ -31,8 +31,10 @@ const checkRewrites = async (request: NextRequestWithAuth) => {
const linkBaseURL = process.env.LINK_URL ?? "http://localhost:3000"; const linkBaseURL = process.env.LINK_URL ?? "http://localhost:3000";
const zammadURL = process.env.ZAMMAD_URL ?? "http://zammad-nginx:8080"; const zammadURL = process.env.ZAMMAD_URL ?? "http://zammad-nginx:8080";
const leafcutterURL = process.env.LEAFCUTTER_URL ?? "http://leafcutter:3000"; const leafcutterURL = process.env.LEAFCUTTER_URL ?? "https://lc.digiresilience.org";
const metamigoURL = process.env.METAMIGO_URL ?? "http://metamigo:3000"; const metamigoURL = process.env.METAMIGO_URL ?? "http://metamigo-frontend:3000";
console.log({ linkBaseURL, zammadURL, leafcutterURL, metamigoURL });
if (request.nextUrl.pathname.startsWith('/proxy/leafcutter')) { if (request.nextUrl.pathname.startsWith('/proxy/leafcutter')) {
const headers = { 'X-Leafcutter-Embedded': "true" }; const headers = { 'X-Leafcutter-Embedded': "true" };

View file

@ -13,13 +13,12 @@ services:
ports: ports:
- "8004:3000" - "8004:3000"
environment: environment:
ZAMMAD_PROXY_URL: ${ZAMMAD_PROXY_URL}
ZAMMAD_API_TOKEN: ${ZAMMAD_API_TOKEN} ZAMMAD_API_TOKEN: ${ZAMMAD_API_TOKEN}
ZAMMAD_VIRUAL_HOST: ${ZAMMAD_VIRTUAL_HOST} ZAMMAD_VIRUAL_HOST: ${ZAMMAD_VIRTUAL_HOST}
LINK_URL: ${LINK_URL} LINK_URL: http://localhost:3000
LEAFCUTTER_URL: http://leafcutter:3000 LEAFCUTTER_URL: https://lc.digiresilience.org
METAMIGO_URL: http://metamigo-frontend:3000 METAMIGO_URL: http://metamigo-frontend:3000
ZAMMAD_URL: http://localhost:8001 ZAMMAD_URL: http://zammad-nginx:8080
NEXTAUTH_URL: ${LINK_URL} NEXTAUTH_URL: ${LINK_URL}
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET} NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
NEXTAUTH_AUDIENCE: ${NEXTAUTH_AUDIENCE} NEXTAUTH_AUDIENCE: ${NEXTAUTH_AUDIENCE}

View file

@ -3,6 +3,7 @@ FROM zammad/zammad-docker-compose:${ZAMMAD_VERSION} AS builder
RUN mkdir -p /opt/zammad/contrib/link/addons RUN mkdir -p /opt/zammad/contrib/link/addons
COPY addons ${ZAMMAD_DIR}/contrib/link/addons COPY addons ${ZAMMAD_DIR}/contrib/link/addons
COPY setup.rb ${ZAMMAD_DIR}/contrib/link/setup.rb COPY setup.rb ${ZAMMAD_DIR}/contrib/link/setup.rb
COPY install.rb ${ZAMMAD_DIR}/contrib/link/install.rb
RUN sed -i '/proxy_set_header X-Forwarded-User "";/d' ${ZAMMAD_DIR}/contrib/nginx/zammad.conf; RUN sed -i '/proxy_set_header X-Forwarded-User "";/d' ${ZAMMAD_DIR}/contrib/nginx/zammad.conf;
USER root USER root
@ -22,13 +23,13 @@ WORKDIR ${ZAMMAD_DIR}
RUN echo "gem 'ruby_openpgp', git: 'https://github.com/throneless-tech/ruby_openpgp', branch: 'signing-and-userids'" >> Gemfile.local RUN echo "gem 'ruby_openpgp', git: 'https://github.com/throneless-tech/ruby_openpgp', branch: 'signing-and-userids'" >> Gemfile.local
RUN echo "gem 'rails-observers'" >> Gemfile.local RUN echo "gem 'rails-observers'" >> Gemfile.local
RUN bundle install --without test development mysql RUN bundle install --without test development mysql
RUN sed -i '/^[[:space:]]*# create install ready file/ i\ RUN sed -i '/^[[:space:]]*# create install ready file/ i\
echo "about to reinstall..."\n\ echo "about to reinstall..."\n\
bundle exec rails runner /opt/zammad/contrib/link/setup.rb\n\ bundle exec rails runner /opt/zammad/contrib/link/setup.rb\n\
bundle exec rake zammad:package:migrate\n\ bundle exec rake zammad:package:migrate\n\
bundle exec rake assets:precompile\n\
' /docker-entrypoint.sh ' /docker-entrypoint.sh
USER zammad
RUN ZAMMAD_SAFE_MODE=1 bundle exec rails runner /opt/zammad/contrib/link/install.rb
FROM node:16.18.0-slim as node FROM node:16.18.0-slim as node
@ -43,5 +44,6 @@ COPY --from=builder ${ZAMMAD_DIR} ${ZAMMAD_DIR}
COPY --from=builder ${SEQUOIA_DIR} ${SEQUOIA_DIR} COPY --from=builder ${SEQUOIA_DIR} ${SEQUOIA_DIR}
COPY --from=builder /usr/local/bundle /usr/local/bundle COPY --from=builder /usr/local/bundle /usr/local/bundle
COPY --from=builder /docker-entrypoint.sh /docker-entrypoint.sh COPY --from=builder /docker-entrypoint.sh /docker-entrypoint.sh
RUN ZAMMAD_SAFE_MODE=1 bundle exec rake assets:precompile

77
docker/zammad/install.rb Normal file
View file

@ -0,0 +1,77 @@
# frozen_string_literal: true
ROOT = '/opt/zammad'
def _read_file(file, fullpath: false)
location = case fullpath
when false
"#{ROOT}/#{file}"
when true
file
else
"#{fullpath}/#{file}"
end
File.binread(location)
end
def _write_file(file, permission, data)
location = "#{ROOT}/#{file}"
# rename existing file if not already the same file
if File.exist?(location)
content_fs = _read_file(file)
if content_fs == data
puts { "NOTICE: file '#{location}' already exists, skip install" }
return true
end
backup_location = "#{location}.save"
puts "NOTICE: backup old file '#{location}' to #{backup_location}"
File.rename(location, backup_location)
end
# check if directories need to be created
directories = location.split '/'
(0..(directories.length - 2)).each do |position|
tmp_path = ''
(1..position).each do |count|
tmp_path = "#{tmp_path}/#{directories[count]}"
end
next if tmp_path == ''
next if File.exist?(tmp_path)
Dir.mkdir(tmp_path, 0o755)
end
# install file
puts "NOTICE: install '#{location}' (#{permission})"
file = File.new(location, 'wb')
file.write(data)
file.close
File.chmod(permission.to_s.to_i(8), location)
true
end
def install(data)
json = _read_file(data, fullpath: true)
package = JSON.parse(json)
package['files'].each do |file|
permission = file['permission'] || '644'
content = Base64.decode64(file['content'])
_write_file(file['location'], permission, content)
end
end
def install_all
packages = Dir.glob('/opt/zammad/contrib/link/addons/*')
packages.each do |package|
puts "Installing #{package} package..."
install(package)
puts 'Installed'
rescue StandardError => e
puts e.message
end
end
puts 'Installing packages...'
install_all

View file

@ -44,6 +44,7 @@ class PGP < ActiveRecord::Migration[5.2]
frontend: true frontend: true
) )
begin
create_table :pgp_keypairs do |t| create_table :pgp_keypairs do |t|
t.string :fingerprint, limit: 250, null: false t.string :fingerprint, limit: 250, null: false
t.binary :public_key, limit: 10.megabytes, null: false t.binary :public_key, limit: 10.megabytes, null: false
@ -52,5 +53,8 @@ class PGP < ActiveRecord::Migration[5.2]
t.timestamps limit: 3, null: false t.timestamps limit: 3, null: false
end end
add_index :pgp_keypairs, [:fingerprint], unique: true add_index :pgp_keypairs, [:fingerprint], unique: true
rescue StandardError => e
puts "NOTICE: #{e.message}"
end
end end
end end