Skip to content

Commit

Permalink
Merge pull request #7215 from freedomofpress/stg-gcloud
Browse files Browse the repository at this point in the history
Use upstream gcloud-sdk image instead of our oudated one
  • Loading branch information
cfm authored Aug 15, 2024
2 parents 42c3a99 + 728ac40 commit bd56cb7
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 151 deletions.
9 changes: 0 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -603,15 +603,6 @@ ci-deb-tests: ## Test SecureDrop Debian packages in CI environment.
@$(SDROOT)/devops/scripts/test-built-packages.sh
@echo

.PHONY: build-gcloud-docker
build-gcloud-docker: ## Build Docker container for Google Cloud SDK.
@echo "Building Docker container for Google Cloud SDK..."
@echo "${GCLOUD_VERSION}" > devops/gce-nested/gcloud-container.ver && \
@docker build --build-arg="GCLOUD_VERSION=${GCLOUD_VERSION}" \
-f devops/docker/Dockerfile.gcloud \
-t "quay.io/freedomofpress/gcloud-sdk:${GCLOUD_VERSION}" .
@echo

.PHONY: vagrant-package
vagrant-package: ## Package a Vagrant box of the last stable SecureDrop release.
@echo "███ Packaging Vagrant box of last stable SecureDrop release."
Expand Down
19 changes: 0 additions & 19 deletions devops/docker/CIDockerfile

This file was deleted.

21 changes: 0 additions & 21 deletions devops/docker/Dockerfile.gcloud

This file was deleted.

19 changes: 0 additions & 19 deletions devops/docker/gce-rpm-key.gpg

This file was deleted.

33 changes: 0 additions & 33 deletions devops/docker/gce-yum-key.gpg

This file was deleted.

17 changes: 0 additions & 17 deletions devops/docker/gcloud-wrapper.sh

This file was deleted.

8 changes: 0 additions & 8 deletions devops/docker/google-cloud-sdk.repo

This file was deleted.

35 changes: 17 additions & 18 deletions devops/gce-nested/ci-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export BUILD_NUM="${CIRCLE_BUILD_NUM}"
export PROJECT_ID="securedrop-ci"
export JOB_NAME="sd-ci-nested"
export GCLOUD_MACHINE_TYPE="c2-standard-8"
GCLOUD_CONTAINER_VER="$(cat "${TOPLEVEL}/devops/gce-nested/gcloud-container.ver")"
export GCLOUD_CONTAINER_VER
export CLOUDSDK_COMPUTE_ZONE="us-west1-c"
export EPHEMERAL_DIRECTORY="/tmp/gce-nested"
Expand All @@ -30,6 +29,7 @@ export SSH_PUBKEY="${SSH_PRIVKEY}.pub"
# retrievable via GOOGLE_CREDENTIALS. Let's read that value, decode it,
# and write it to disk in the CI environment so the gcloud tooling
# can authenticate.
# This function is called multiple times and must be idempotent.
function generate_gce_creds_file() {
# First check if there is an existing cred file
if [ ! -f "${GCE_CREDS_FILE}" ]; then
Expand All @@ -48,26 +48,25 @@ function generate_gce_creds_file() {
fi
fi
fi
}

# Wrapper function to communicate with the gcloud API. Ensure gcloud-sdk
# container is running, and if so, pass all args to it.
function gcloud_call() {
if ! (docker ps | grep -q gcloud_tool); then
docker run --rm \
--env="CLOUDSDK_COMPUTE_ZONE=${CLOUDSDK_COMPUTE_ZONE}" \
--volume "${EPHEMERAL_DIRECTORY}/gce.pub:/gce.pub" \
--volume "${GCE_CREDS_FILE}:/gce-svc-acct.json" \
--name gcloud_tool -d \
"quay.io/freedomofpress/gcloud-sdk:${GCLOUD_CONTAINER_VER}" \
background >/dev/null 2>&1
# Give container a moment for gcloud tooling to authenticate
# Kept falling over on first calls without this
sleep 3
# Prime the "gcloud-config" container by authenticating from $GCE_CREDS_FILE.
if ! docker inspect --format '{{ .Id }}' gcloud-config > /dev/null 2>&1; then
docker run \
--env="CLOUDSDK_COMPUTE_ZONE=${CLOUDSDK_COMPUTE_ZONE}" \
--volume "${GCE_CREDS_FILE}:/gce-svc-acct.json" \
--name gcloud-config \
gcr.io/google.com/cloudsdktool/google-cloud-cli:stable \
gcloud auth activate-service-account --key-file /gce-svc-acct.json
fi
}

docker exec -i gcloud_tool \
/usr/bin/gcloud --project "${PROJECT_ID}" "$@"
# Each gcloud_call() invocation just runs a fresh (note "--rm") instance of the "google-cloud-cli" container primed from "gcloud-config" above.
function gcloud_call() {
docker run --rm \
--volumes-from gcloud-config \
--env="CLOUDSDK_COMPUTE_ZONE=${CLOUDSDK_COMPUTE_ZONE}" \
gcr.io/google.com/cloudsdktool/google-cloud-cli:stable \
gcloud --project "${PROJECT_ID}" "$@"
}


Expand Down
6 changes: 0 additions & 6 deletions devops/gce-nested/ci-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ set -o pipefail

export BASE_OS="${BASE_OS:-focal}"

# Temporary workaround for old gcloud-sdk image
sudo mkdir -p /etc/systemd/system/docker.service.d
echo -e "[Service]\nEnvironment=\"DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE=true\"" | sudo tee -a /etc/systemd/system/docker.service.d/env.conf
sudo systemctl daemon-reload
sudo systemctl restart docker

./devops/gce-nested/gce-start.sh
./devops/gce-nested/gce-runner.sh
./devops/gce-nested/gce-stop.sh
8 changes: 7 additions & 1 deletion devops/scripts/boot-strap-venv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ function virtualenv_bootstrap() {
then
p=$(command -v "python${PYTHON_VERSION}" 2> /dev/null || command -v python3)
echo "Creating ${p} virtualenv in ${VENV}"
"${p}" -m venv "${VENV}"
# be flexible in venv creation, e.g. staging has virtualenv while
# deb-tests (GHA runner) has python3-venv
if command -v virtualenv > /dev/null; then
virtualenv -p "${p}" "${VENV}"
else
"${p}" -m venv "${VENV}"
fi
fi

PIP_CONSTRAINT=${DEV_CONSTRAINT} "${VENV}/bin/pip" install -q -r "securedrop/requirements/python3/develop-requirements.txt"
Expand Down

0 comments on commit bd56cb7

Please sign in to comment.