-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ytimocin <[email protected]>
- Loading branch information
Showing
9 changed files
with
248 additions
and
85 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
.github/actions/create-local-registry/insecure/action.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: "Create a secure local registry" | ||
description: | | ||
This action creates a local registry for the images to be pushed to. | ||
It uses the `docker` CLI to create a registry container and then starts it. | ||
The registry is then available at `localhost:5000` by default. | ||
inputs: | ||
registry-name: | ||
description: "The name of the local registry" | ||
required: true | ||
default: "radius-registry" | ||
registry-server: | ||
description: "The server name for the local registry" | ||
required: true | ||
default: "localhost" | ||
registry-port: | ||
description: "The port for the local registry" | ||
required: true | ||
default: "5000" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Create certificates for local registry | ||
shell: bash | ||
run: | | ||
create_openssl_cfg() { | ||
CFG=$( | ||
cat <<'EOF' | ||
[req] | ||
distinguished_name = subject | ||
x509_extensions = x509_ext | ||
prompt = no | ||
[subject] | ||
CN = localhost | ||
[x509_ext] | ||
basicConstraints = critical, CA:TRUE | ||
subjectKeyIdentifier = hash | ||
authorityKeyIdentifier = keyid:always, issuer:always | ||
keyUsage = critical, cRLSign, digitalSignature, keyCertSign | ||
nsComment = "OpenSSL Generated Certificate" | ||
subjectAltName = @alt_names | ||
[alt_names] | ||
DNS.1 = ${{ inputs.registry-name }} | ||
DNS.2 = ${{ inputs.registry-server }} | ||
EOF | ||
) | ||
echo "$CFG" | ||
} | ||
# Create a temporary directory to store the certificates | ||
temp_cert_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'temp_cert_dir') | ||
echo "TEMP_CERT_DIR=$temp_cert_dir" >> $GITHUB_ENV | ||
pushd $temp_cert_dir | ||
# Create the directory for the certificates | ||
mkdir -p certs/${{ inputs.registry-server }} | ||
echo "==== Generate the openssl config" | ||
create_openssl_cfg >req.cnf | ||
echo "==== Create the self signed certificate certificate and client key files" | ||
openssl req -x509 \ | ||
-nodes \ | ||
-days 365 \ | ||
-newkey rsa:4096 \ | ||
-keyout certs/${{ inputs.registry-server }}/client.key \ | ||
-out certs/${{ inputs.registry-server }}/client.crt \ | ||
-config req.cnf \ | ||
-sha256 | ||
- name: Add the certificate to the system trust store | ||
shell: bash | ||
run: | | ||
sudo apt install ca-certificates | ||
sudo cp $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}/client.crt /usr/local/share/ca-certificates/${{ inputs.registry-server }}.crt | ||
sudo cp $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}/client.crt /usr/local/share/ca-certificates/${{ inputs.registry-name }}.crt | ||
sudo update-ca-certificates | ||
- name: Create local Docker registry | ||
shell: bash | ||
run: | | ||
if [ "$(docker inspect -f '{{.State.Running}}' "${{ inputs.registry-name }}" 2>/dev/null || true)" != 'true' ]; then | ||
echo "==== Creating a docker registry" | ||
docker run -d \ | ||
-p ${{ inputs.registry-port }}:5000 \ | ||
--restart=always \ | ||
--name ${{ inputs.registry-name }} \ | ||
-v $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}:/certs \ | ||
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/client.crt \ | ||
-e REGISTRY_HTTP_TLS_KEY=/certs/client.key \ | ||
registry:2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: "Create a secure local registry" | ||
description: | | ||
This action creates a local registry for the images to be pushed to. | ||
It uses the `docker` CLI to create a registry container and then starts it. | ||
The registry is then available at `localhost:5000` by default. | ||
inputs: | ||
registry-name: | ||
description: "The name of the local registry" | ||
required: true | ||
default: "radius-registry" | ||
registry-server: | ||
description: "The server name for the local registry" | ||
required: true | ||
default: "localhost" | ||
registry-port: | ||
description: "The port for the local registry" | ||
required: true | ||
default: "5000" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Create certificates for local registry | ||
shell: bash | ||
run: | | ||
create_openssl_cfg() { | ||
CFG=$( | ||
cat <<'EOF' | ||
[req] | ||
distinguished_name = subject | ||
x509_extensions = x509_ext | ||
prompt = no | ||
[subject] | ||
CN = localhost | ||
[x509_ext] | ||
basicConstraints = critical, CA:TRUE | ||
subjectKeyIdentifier = hash | ||
authorityKeyIdentifier = keyid:always, issuer:always | ||
keyUsage = critical, cRLSign, digitalSignature, keyCertSign | ||
nsComment = "OpenSSL Generated Certificate" | ||
subjectAltName = @alt_names | ||
[alt_names] | ||
DNS.1 = ${{ inputs.registry-name }} | ||
DNS.2 = ${{ inputs.registry-server }} | ||
EOF | ||
) | ||
echo "$CFG" | ||
} | ||
# Create a temporary directory to store the certificates | ||
temp_cert_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'temp_cert_dir') | ||
echo "TEMP_CERT_DIR=$temp_cert_dir" >> $GITHUB_ENV | ||
pushd $temp_cert_dir | ||
# Create the directory for the certificates | ||
mkdir -p certs/${{ inputs.registry-server }} | ||
echo "==== Generate the openssl config" | ||
create_openssl_cfg >req.cnf | ||
echo "==== Create the self signed certificate certificate and client key files" | ||
openssl req -x509 \ | ||
-nodes \ | ||
-days 365 \ | ||
-newkey rsa:4096 \ | ||
-keyout certs/${{ inputs.registry-server }}/client.key \ | ||
-out certs/${{ inputs.registry-server }}/client.crt \ | ||
-config req.cnf \ | ||
-sha256 | ||
- name: Add the certificate to the system trust store | ||
shell: bash | ||
run: | | ||
sudo apt install ca-certificates | ||
sudo cp $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}/client.crt /usr/local/share/ca-certificates/${{ inputs.registry-server }}.crt | ||
sudo cp $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}/client.crt /usr/local/share/ca-certificates/${{ inputs.registry-name }}.crt | ||
sudo update-ca-certificates | ||
- name: Create local Docker registry | ||
shell: bash | ||
run: | | ||
if [ "$(docker inspect -f '{{.State.Running}}' "${{ inputs.registry-name }}" 2>/dev/null || true)" != 'true' ]; then | ||
echo "==== Creating a docker registry" | ||
docker run -d \ | ||
-p ${{ inputs.registry-port }}:5000 \ | ||
--restart=always \ | ||
--name ${{ inputs.registry-name }} \ | ||
-v $TEMP_CERT_DIR/certs/${{ inputs.registry-server }}:/certs \ | ||
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/client.crt \ | ||
-e REGISTRY_HTTP_TLS_KEY=/certs/client.key \ | ||
registry:2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,3 @@ runs: | |
shell: bash | ||
run: chmod +x rad | ||
working-directory: dist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.