Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Google Cloud Platform (GCP) provider support #36

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM node:22.5.1-bookworm-slim AS build
ARG NODE_VERSION="20.16.0-bookworm-slim"
FROM node:${NODE_VERSION} AS build

RUN apt update && apt install -y \
curl \
Expand All @@ -17,7 +18,27 @@ RUN curl "https://get.pulumi.com/releases/sdk/pulumi-${PULUMI_VERSION}-linux-x64
#
# Cloudy Pad
#
FROM node:22.5.1-bookworm-slim

# Compile Typescript code in dedicated image to avoid dev dependencies in final image
FROM build AS tsc

WORKDIR /build

COPY package.json package.json
COPY package-lock.json package-lock.json
RUN npm install

# ansible required for build as packaged with node code
COPY ansible ansible
COPY src src
COPY LICENSE.txt tsconfig.json .

RUN npm run build

#
# Final Cloudypad image
#
FROM node:${NODE_VERSION}

# Global tooling
RUN apt update && apt install -y \
Expand Down Expand Up @@ -47,17 +68,15 @@ RUN ansible-galaxy collection install -r ansible/requirements.yml -p /usr/share/
ENV ANSIBLE_STDOUT_CALLBACK=community.general.unixy

# Deps
ENV NODE_ENV=production
COPY package.json package.json
COPY package-lock.json package-lock.json
RUN npm install
RUN npm ci --omit dev

# Build and install globally
COPY ansible ansible
COPY src src
COPY LICENSE.txt tsconfig.json .
# Copy built app directly
COPY --from=tsc /build/dist dist/
COPY LICENSE.txt .


RUN npm run build
RUN npm install -g
RUN npm install --global

ENTRYPOINT ["cloudypad"]
16 changes: 15 additions & 1 deletion cloudypad.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ if [ $container_build_result -ne 0 ]; then
exit 1
fi

# Create and run a container for Cloudy Pad
# Builds a docker command with required volumes and env vars so that
# running container matches host:
# - user (uid and main group)
# - mount important directories (such as home and ssh)
# - mount Cloud credentials if available
# - add environment variable matching host
run_cloudypad_docker() {

# Ensure Cloudy Pad home exists and is secure enough
Expand All @@ -80,11 +87,12 @@ run_cloudypad_docker() {

# List of directories to mount only if they exist
local mounts=(
"$HOME/.cloudypad"
"$HOME/.ssh"
"$HOME/.aws"
"$HOME/.cloudypad"
"$HOME/.paperspace"
"$HOME/.azure"
"$HOME/.config/gcloud"
)

# Build run command with proper directories
Expand Down Expand Up @@ -119,6 +127,12 @@ run_cloudypad_docker() {
# Azure
"AZURE_LOCATION" "AZURE_SUBSCRIPTION_ID" "AZURE_CLIENT_ID" "AZURE_SECRET" "AZURE_TENANT"
"ARM_SUBSCRIPTION_ID" "ARM_CLIENT_ID" "ARM_CLIENT_SECRET" "ARM_TENANT_ID"

# Google
"GOOGLE_PROJECT" "GOOGLE_CLOUD_PROJECT" "GCLOUD_PROJECT" "CLOUDSDK_CORE_PROJECT"
"GOOGLE_REGION" "GCLOUD_REGION" "CLOUDSDK_COMPUTE_REGION"
"GOOGLE_ZONE" "GCLOUD_ZONE" "CLOUDSDK_COMPUTE_ZONE"
"GOOGLE_IMPERSONATE_SERVICE_ACCOUNT"
)

for env_var in "${env_vars[@]}"; do
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
yq
jq
gh

google-cloud-sdk
];

shellHook = ''
Expand Down
Loading
Loading