This project provides a Dockerized version of GAM7, the Google Workspace Management Tool, optimized for use with Google Cloud and Artifact Registry.
- Prerequisites
- Project Structure
- Getting Started
- Deploying to Google Artifact Registry
- Using GAM7 Docker with Google Cloud Shell
- Job Scheduling in Google Cloud
- Multi-Platform Support
- Troubleshooting
- Advanced Usage
- Contributing
- License
- Support
- Google Cloud account with billing enabled
- Google Cloud SDK (
gcloud) installed and configured - Docker installed on your local system (for building and testing)
- Docker Compose V2 installed on your system
- Basic understanding of GAM and Google Workspace administration
The project consists of the following key files and directories:
Dockerfile: Defines the Docker image for GAM7docker-compose.yml: Configures the Docker containerrequirements.txt: Lists Python dependenciesscripts/: Directory containing scripts for setup and entrypointdocker-entrypoint.sh: Script that runs when the container startssetup-gam7-docker.sh: Script to set up the environment in Google Cloud Shell
GAMConfig/: Directory for GAM configuration filesGAMWork/: Directory for GAM work files
-
Create a directory structure for your GAM configuration:
mkdir -p GAMConfig/{au,nz,us} mkdir -p GAMWork/{au,nz,us} -
Place your GAM configuration files (
client_secrets.json,oauth2.txt,oauth2service.json) in the appropriate subdirectories ofGAMConfig. -
Ensure your
gam.cfgfile is present in theGAMConfigdirectory.
-
Enable the Artifact Registry API in your Google Cloud project:
gcloud services enable artifactregistry.googleapis.com -
Create a repository in Artifact Registry:
gcloud artifacts repositories create gam7-repo --repository-format=docker --location=us-central1 --description="GAM7 Docker images" -
Configure Docker to use Google Cloud as a credential helper:
gcloud auth configure-docker us-central1-docker.pkg.dev
-
Build your Docker image:
docker build -t us-central1-docker.pkg.dev/gam-project-5y3-yuq-dpk/gam7-repo/gam-docker:latest . -
Push the image to Artifact Registry:
docker push us-central1-docker.pkg.dev/gam-project-5y3-yuq-dpk/gam7-repo/gam-docker:latest
-
Update your
docker-compose.ymlto use the image from Artifact Registry:services: gam-docker: image: us-central1-docker.pkg.dev/gam-project-5y3-yuq-dpk/gam7-repo/gam-docker:latest platform: linux/amd64 volumes: - ./GAMConfig:/home/gam/GAMConfig - ./GAMWork:/home/gam/GAMWork environment: - PATH=/home/gam/bin:/home/gam/bin/gam7:$PATH - GAMCFGDIR=/home/gam/GAMConfig entrypoint: ["/docker-entrypoint.sh"] command: tail -f /dev/null tty: true stdin_open: true restart: unless-stopped
Google Cloud Shell provides a convenient environment for managing your Google Cloud resources. Here's how to use GAM7 Docker in Cloud Shell:
-
Open Google Cloud Shell and clone your repository:
git clone https://phaley@bitbucket.org/GJGTech/gam-docker.git cd gam-docker -
Run the setup script:
./scripts/setup-gam7-docker.sh
This script installs Docker Compose, configures Docker for Artifact Registry, pulls the latest image, and starts the container.
-
To run GAM commands:
docker-compose exec gam-docker gam version
For scheduling GAM7 tasks, use Google Cloud Scheduler with Cloud Run:
-
Deploy your GAM7 container to Cloud Run:
gcloud run deploy gam7-service --image us-central1-docker.pkg.dev/gam-project-5y3-yuq-dpk/gam7-repo/gam-docker:latest --platform managed
-
Create a Cloud Scheduler job:
gcloud scheduler jobs create http gam7-job \ --schedule="0 2 * * *" \ --uri="https://gam7-service-xxxx-uc.a.run.app/run-gam-command" \ --http-method=POST \ --message-body='{"command": "update group"}'
Our Docker image supports both AMD64 and ARM64 architectures. To build a multi-platform image:
-
Set up Docker BuildX:
docker buildx create --name mybuilder --use
-
Build and push the multi-platform image:
docker buildx build --platform linux/amd64,linux/arm64 \ -t us-central1-docker.pkg.dev/gam-project-5y3-yuq-dpk/gam7-repo/gam-docker:latest \ --push .
If you encounter issues running GAM commands:
-
Check the GAM executable location:
docker-compose exec gam-docker which gam -
Verify permissions:
docker-compose exec gam-docker ls -l /home/gam/bin/gam7/gam -
Fix permissions if necessary:
docker-compose exec gam-docker chmod +x /home/gam/bin/gam7/gam -
If you're having issues with the container not starting or exiting immediately, check the Docker logs:
docker-compose logs gam-docker
-
If you need to modify the entrypoint script:
nano scripts/docker-entrypoint.sh
Remember to rebuild your Docker image after making changes to this script.
To customize the build process, use build args in your docker-compose.yml:
services:
gam-docker:
build:
context: .
args:
CUSTOM_ARG: valueUpdate the Dockerfile to use these args:
ARG CUSTOM_ARG
RUN echo $CUSTOM_ARGIf you need to update or add Python dependencies, modify the requirements.txt file. Then rebuild your Docker image to apply the changes.
Contributions are welcome! Please feel free to submit a Pull Request.
For issues related to this Docker setup, please open an issue in this repository. For GAM-specific questions, refer to the official GAM documentation.