Skip to content

Commit

Permalink
fix: Allow pushing to insecure registries without a token
Browse files Browse the repository at this point in the history
  • Loading branch information
vehagn committed Jan 18, 2024
1 parent 41cbce5 commit 07cfbc2
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [3.0.2] - 2024-01-18

### Fixed

- Allow pushing to insecure registries without a token

## [3.0.1] - 2024-01-18

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "containerify",
"version": "3.0.1",
"version": "3.0.2",
"description": "Build node.js docker images without docker",
"main": "./lib/cli.js",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ exitWithErrorIf(
!options.toRegistry && !options.toTar && !options.toDocker,
"Must specify either --toTar, --toRegistry or --toDocker",
);
exitWithErrorIf(!!options.toRegistry && !options.toToken, "A token must be given when uploading to docker hub");

if (options.toRegistry && !options.toRegistry.endsWith("/")) options.toRegistry += "/";
if (options.fromRegistry && !options.fromRegistry.endsWith("/")) options.fromRegistry += "/";
Expand Down
10 changes: 4 additions & 6 deletions src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ function uploadContent(
logger.debug("Uploading: ", file);
let url = uploadUrl;
if (fileConfig.digest) url += (url.indexOf("?") == -1 ? "?" : "&") + "digest=" + fileConfig.digest;
const options = createHttpOptions("PUT", url, {
authorization: auth,
"content-length": fileConfig.size,
"content-type": contentType,
});
const headers: OutgoingHttpHeaders = { "content-length": fileConfig.size, "content-type": contentType};
if (auth) headers.authorization = auth;
const options = createHttpOptions("PUT", url, headers);
logger.debug(options.method, url);
const req = request(options, allowInsecure, (res) => {
logger.debug(res.statusCode, res.statusMessage, res.headers["content-type"], res.headers["content-length"]);
Expand Down Expand Up @@ -222,7 +220,7 @@ export async function createRegistry(
const url = `${registryBaseUrl}${image.path}/blobs/uploads/${parameters.size > 0 ? "?" + parameters : ""}`;
const options: https.RequestOptions = URL.parse(url);
options.method = "POST";
options.headers = { authorization: auth };
if (auth) options.headers = { authorization: auth };
request(options, allowInsecure, (res) => {
logger.debug("POST", `${url}`, res.statusCode);
if (res.statusCode == 202) {
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = "3.0.1";
export const VERSION = "3.0.2";
52 changes: 52 additions & 0 deletions tests/localtest/test-insecure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

set -e

export DOCKER_CONFIG=tmp
LOCAL_REGISTRY=127.0.0.1

rm -rf tmp
mkdir tmp

printf "* Stopping any running local containerify test registry...\n"
docker stop registry-containerify-insecure-test >/dev/null 2>&1 || echo "No running container registry, so nothing to stop"

printf "* Starting local containerify test registry on port 5443...\n"
docker run -d \
--rm \
--name registry-containerify-insecure-test \
-e REGISTRY_HTTP_ADDR=0.0.0.0:5443 \
-p 5443:5443 \
registry:2 > /dev/null

printf "* Pulling node:alpine as base image...\n"
docker pull node:alpine &> /dev/null

printf "* Pushing base image to local containerify test registry...\n"
docker tag node:alpine ${LOCAL_REGISTRY}:5443/node > /dev/null
docker push ${LOCAL_REGISTRY}:5443/node > /dev/null

printf "* Running containerify to pull from and push result to the local containerify test registry...\n"
cd ../integration/app
npm ci
cd ../../localtest
../../lib/cli.js --registry http://${LOCAL_REGISTRY}:5443/v2/ \
--fromImage node \
--toImage containerify-integration-test:localtest \
--allowInsecureRegistries --doCrossMount \
--folder ../integration/app --setTimeStamp "2024-01-18T13:33:33.337Z"

printf "\n* Pulling image from registry to local docker daemon...\n"
docker pull ${LOCAL_REGISTRY}:5443/containerify-integration-test:localtest &> /dev/null

printf "* Running image on local docker daemon...\n"
docker run --rm -it ${LOCAL_REGISTRY}:5443/containerify-integration-test:localtest

printf "\n* Deleting image from registry to local docker daemon...\n"
docker rmi ${LOCAL_REGISTRY}:5443/containerify-integration-test:localtest > /dev/null

printf "* Stopping local containerify test registry...\n"
docker stop registry-containerify-insecure-test > /dev/null
rm -rf tmp

printf "\nSUCCESS!\n"
10 changes: 8 additions & 2 deletions tests/localtest/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ docker push ${LOCAL_REGISTRY}:5443/node > /dev/null

printf "* Running containerify to pull from and push result to the local containerify test registry...\n"
cd ../integration/app
npm install
npm ci
cd ../../localtest
../../lib/cli.js --fromImage node --doCrossMount --registry https://${LOCAL_REGISTRY}:5443/v2/ --toImage containerify-integration-test:localtest --folder ../integration/app --setTimeStamp "2023-03-07T12:53:10.471Z" --allowInsecureRegistries --token "Basic $BASICAUTH"
../../lib/cli.js --registry https://${LOCAL_REGISTRY}:5443/v2/ \
--allowInsecureRegistries \
--token "Basic $BASICAUTH" \
--fromImage node \
--toImage containerify-integration-test:localtest \
--doCrossMount \
--folder ../integration/app --setTimeStamp "2023-03-07T12:53:10.471Z"


printf "\n* Pulling image from registry to local docker daemon...\n"
Expand Down

0 comments on commit 07cfbc2

Please sign in to comment.