Last active
November 29, 2024 17:35
-
-
Save williamfalinski/e060013104362d3df97dccb3380580ff to your computer and use it in GitHub Desktop.
docker gcloud helper
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
=========================================================================== | |
DOCKER UTILS | |
# delete all images | |
sudo docker image prune --all --force | |
# delete specific image | |
sudo docker image rm ec3ca0296e06 | |
# list images | |
sudo docker image ls | |
# Build local | |
sudo docker build -t docker_name . | |
# test run in 8080 | |
sudo docker run --rm -p 8080:8080 -e PORT=8080 docker_name | |
# test run in 8080 python output unbuffered | |
sudo docker run --rm -p 8080:8080 -e PORT=8080 -e PYTHONUNBUFFERED=1 docker_name | |
=========================================================================== | |
# GCLOUD (RUN) CLI UTILS | |
sudo gcloud auth login | |
sudo gcloud config set project 'PROJECT' | |
sudo gcloud auth configure-docker LOCATION_ARTIFACT | |
# 1 Build local and push to artifact | |
# Commit docker to gcloud | |
sudo docker tag TAG_ID LOCATION_ARTIFACT/GCP_PROJECT_ID/ARTIFACT_RESGISTRY/CUSTOM_NAME | |
# Push docker to artifact | |
sudo docker push LOCATION_ARTIFACT/GCP_PROJECT_ID/ARTIFACT_RESGISTRY/CUSTOM_NAME | |
# 2 Build and push using cloudbuild (need to create cloudbuild.yaml) | |
# Login | |
sudo gcloud auth login | |
# Set project | |
sudo gcloud config set project 'PROJECT' | |
# Build | |
sudo gcloud builds submit --config cloudbuild.yaml --region us-central1 | |
# cloudbuild.yaml sample: | |
""" | |
steps: | |
- id: "docker-build" | |
timeout: 1200s | |
name: "gcr.io/cloud-builders/docker" | |
args: ["build", "-t", "us-central1-docker.pkg.dev/${_PROJECT_ID}/${_REPO_NAME}/${_DOCKER_NAME}", "."] | |
- id: "push-docker-image" | |
name: "gcr.io/cloud-builders/docker" | |
args: ["push", "us-central1-docker.pkg.dev/${_PROJECT_ID}/${_REPO_NAME}/${_DOCKER_NAME}"] | |
waitFor: ["docker-build"] | |
substitutions: | |
_REPO_NAME: "YOUR ARTIFACT" | |
_PROJECT_ID: "YOUR PROJECT ID" | |
_DOCKER_NAME: "YOUR DOCKER CUSTOM NAME" | |
""" | |
=========================================================================== | |
# AWS (ECR) CLI UTILS | |
sudo docker build -t docker_name . | |
sudo docker run --rm -p 8080:8080 docker_name | |
# Follow the steps to push from AWS: | |
https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html | |
IF YOU ARE USING SSO PROFILE CHANGE FROM: | |
aws ecr get-login-password --region us-east-1 | ... | |
TO | |
# Get hash using SSO and login docker | |
aws ecr get-login-password --region us-east-1 --profile YOUR-PROFILE | ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment