Skip to content

Instantly share code, notes, and snippets.

@rgolangh
Last active October 31, 2023 11:15
Show Gist options
  • Select an option

  • Save rgolangh/ec8f87b7ed952c4767d29e16c8bf434f to your computer and use it in GitHub Desktop.

Select an option

Save rgolangh/ec8f87b7ed952c4767d29e16c8bf434f to your computer and use it in GitHub Desktop.
Create Janus backstage-showcase image with orchestrator plugins
#!/bin/bash -xe
pushd $(mktemp -d -p .)
cleanup() {
popd
}
trap cleanup EXIT SIGINT SIGTERM
VERDACCIO_CONF=$(mktemp -p . XXX-verdaccio.conf)
BACKSTAGE_PLUGINS_DOCKERFILE=$(mktemp -p . XXX-backstage-plugins.Dockerfile)
BACKSTAGE_PLUGINS_REPO=https://github.com/caponetto/backstage-plugins
BACKSTAGE_PLUGINS_REPO_REF=KOGITO-9778
BACKSTAGE_SHOWCASE_REPO=https://github.com/caponetto/backstage-showcase
BACKSTAGE_SHOWCASE_REPO_REF=changes-needed
BACKSTAGE_UNPUBLISHED_PLUGINS="\
orchestrator-common \
orchestrator-backend \
orchestrator"
cat <<EOF > ${VERDACCIO_CONF}
storage: /verdaccio/storage
auth:
htpasswd:
file: ./htpasswd
uplinks:
npmjs:
url: https://registry.npmjs.org/
packages:
'@*/*':
access: \$anonymous
publish: \$anonymous
proxy: npmjs
'**':
proxy: npmjs
access: \$anonymous
publish: \$anonymous
log: { type: stdout, format: pretty, level: http }
EOF
cat <<EOF > ${BACKSTAGE_PLUGINS_DOCKERFILE}
FROM registry.access.redhat.com/ubi9/nodejs-18:1-70 AS skeleton
USER 0
RUN /bin/bash -c 'dnf install -y -q --allowerasing --nobest nodejs-devel nodejs-libs \
openssl openssl-devel ca-certificates make cmake cpp gcc gcc-c++ zlib zlib-devel brotli brotli-devel python3 nodejs-packaging && \
dnf update -y && dnf clean all'
RUN git clone --depth 1 -b ${BACKSTAGE_PLUGINS_REPO_REF} ${BACKSTAGE_PLUGINS_REPO}
WORKDIR backstage-plugins
RUN npm install --global yarn@1.22.19
RUN npm set registry http://localhost:4873/
RUN echo -e "_auth = 123\nemail = a.a.com\n" > ~/.npmrc
WORKDIR /opt/app-root/src/backstage-plugins/plugins
CMD /bin/bash -c 'for i in ${BACKSTAGE_UNPUBLISHED_PLUGINS};do \
pushd \${i} ;\
yarn install; \
yarn publish --registry http://localhost:4873 --force --non-interactive; \
popd ;\
done'
EOF
if ! $(podman container exists verdaccio ) ; then podman run --rm -it -d --user=verdaccio --name verdaccio -v ${PWD}/${VERDACCIO_CONF}:/verdaccio/conf/config.yaml:Z \
-p 4873:4873 docker.io/verdaccio/verdaccio ;fi
podman build . -f ${BACKSTAGE_PLUGINS_DOCKERFILE} -t backstage-plugins --network host
podman run --rm -it --network host --name backstage-plugins backstage-plugins
git clone --depth 1 -b ${BACKSTAGE_SHOWCASE_REPO_REF} ${BACKSTAGE_SHOWCASE_REPO} && cd backstage-showcase
sed -i '/YARN install/ i RUN \$YARN cache clean --pattern orchestrator' docker/Dockerfile
sed -i 's/YARN install/YARN install --update-checksums/' docker/Dockerfile
podman build . -f docker/Dockerfile --network host -t quay.io/rgolangh/orchestrator
@masayag
Copy link

masayag commented Oct 31, 2023

I changed this to make it work from the script (note the path changed from /tmp to local dir for debug):

#!/bin/bash -xe

RUN_DIR=$(mktemp -d)/
pushd $RUN_DIR

cleanup() {
  set +e
  echo "Cleaning up before exit..."
  podman stop verdaccio
  podman ps --all --format "{{.ID}}\t{{.Image}}" | grep "localhost/backstage-plugins:latest" | awk '{print $1}' | xargs podman rm
  podman ps --all --filter label=remove=true | awk '$7 == "Exited" {print $1}' | xargs -r podman rm
  set -e

  echo "Run from directory: $RUN_DIR"
}

trap cleanup EXIT

BACKSTAGE_PLUGINS_REPO=https://github.com/caponetto/backstage-plugins
BACKSTAGE_PLUGINS_REPO_REF=KOGITO-9778
BACKSTAGE_SHOWCASE_REPO=https://github.com/caponetto/backstage-showcase
BACKSTAGE_SHOWCASE_REPO_REF=changes-needed

echo "-----> Create verdaccio.conf"
cat <<EOF > ./verdaccio.conf
storage: /verdaccio/storage
auth:
  htpasswd:
    file: ./htpasswd
uplinks:
  npmjs:
    url: https://registry.npmjs.org/
packages:
  '@*/*':
    access: \$anonymous
    publish: \$anonymous
    proxy: npmjs
  '**':
    proxy: npmjs
    access: \$anonymous
    publish: \$anonymous
log: { type: stdout, format: pretty, level: http }
EOF

echo "-----> Create backstage-plugins.Dockerfile"
cat <<EOF > ./backstage-plugins.Dockerfile
FROM registry.access.redhat.com/ubi9/nodejs-18:1-70 AS skeleton
USER 0

RUN /bin/bash -c 'dnf install -y -q --allowerasing --nobest nodejs-devel nodejs-libs \
  openssl openssl-devel ca-certificates make cmake cpp gcc gcc-c++ zlib zlib-devel brotli brotli-devel python3 nodejs-packaging && \
  dnf update -y && dnf clean all'

RUN git clone --depth 1 -b ${BACKSTAGE_PLUGINS_REPO_REF} ${BACKSTAGE_PLUGINS_REPO}

WORKDIR backstage-plugins
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

RUN npm install --global yarn@1.22.19
RUN npm set registry http://localhost:4873/
RUN echo -e "_auth = 123\nemail = a.a.com\n" > ~/.npmrc

CMD ["/entrypoint.sh"]
EOF

cat <<EOF > ./entrypoint.sh
#!/bin/bash -xv

cd plugins
for i in orchestrator-common orchestrator orchestrator-backend; do
  echo "Install plugin \$i"
  cd \$i
  yarn install
  yarn publish --registry http://localhost:4873 --force --non-interactive
  cd ..
done
cd ..
EOF

if ! podman container inspect -f '{{.State.Status}}' verdaccio &> /dev/null || [ "$(podman container inspect -f '{{.State.Status}}' verdaccio)" != "running" ]; then
  echo "-----> Run private npm repository container"
  podman run --rm --label remove=true -it -d --user=verdaccio --name verdaccio -v ./verdaccio.conf:/verdaccio/conf/config.yaml:Z \
    -p 4873:4873  docker.io/verdaccio/verdaccio
fi

echo "-----> Build backstage-plugins container"
podman build . -f ./backstage-plugins.Dockerfile -t backstage-plugins --network host

echo "-----> Run backstage-plugins container"
podman run --label remove=true -it --network host backstage-plugins

echo "-----> Build showcase image"
git clone --depth 1 -b ${BACKSTAGE_SHOWCASE_REPO_REF} ${BACKSTAGE_SHOWCASE_REPO} && cd backstage-showcase
podman build . -f docker/Dockerfile --network host

popd 

@rgolangh
Copy link
Author

I'm going to add a yarn cache cleanup, because it fails if you want to make a change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment