version: 3 dotenv: - .env vars: DOCKER_FILE: modules/jenkins/docker/Dockerfile JCASC_CONFIG_PATH: modules/jenkins/jcasc/ PLUGINS_FILE: modules/jenkins/plugins/plugins.txt REPOSITORY: sh: grep 'LABEL repository=' {{.DOCKER_FILE}} | cut -d '"' -f 2 VERSION: sh: grep 'LABEL version=' {{.DOCKER_FILE}} | cut -d '"' -f 2 tasks: docker:build: desc: Build Jenkins image cmd: | docker build \ --build-arg AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" \ --build-arg AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" \ --build-arg JCASC_CONFIG_PATH="{{.JCASC_CONFIG_PATH}}" \ --build-arg JENKINS_ADMIN_DESC="$JENKINS_ADMIN_DESC" \ --build-arg JENKINS_ADMIN_EMAIL="$JENKINS_ADMIN_EMAIL" \ --build-arg JENKINS_ADMIN_NAME="$JENKINS_ADMIN_NAME" \ --build-arg JENKINS_ADMIN_PASS="$JENKINS_ADMIN_PASS" \ --build-arg JENKINS_ADMIN_USER="$JENKINS_ADMIN_USER" \ --build-arg GITHUB_ACCESS_TOKEN="$GITHUB_ACCESS_TOKEN" \ --build-arg GITHUB_USER="$GITHUB_USER" \ --build-arg PLUGINS_FILE="{{.PLUGINS_FILE}}" \ --file {{.DOCKER_FILE}} \ --tag {{.REPOSITORY}}/jenkins:{{.VERSION}} \ --no-cache \ . silent: true docker:run: desc: Run local Jenkins container cmd: | docker run \ --detach \ --name jenkins \ --publish 8080:8080 \ --volume /var/run/docker.sock:/var/run/docker.sock \ --user root \ {{.REPOSITORY}}/jenkins:{{.VERSION}} silent: true docker:tag: desc: "Tag Jenkins image" cmd: docker tag {{.REPOSITORY}}/jenkins:{{.VERSION}} {{.REPOSITORY}}/jenkins:latest silent: true docker:push: desc: Push Jenkins image to DockerHub cmds: - docker push {{.REPOSITORY}}/jenkins:{{.VERSION}} - docker push {{.REPOSITORY}}/jenkins:latest silent: true tf:init: desc: Initialize Terraform working directory cmd: terraform init -upgrade silent: true tf:validate: desc: Validate the Terraform configuration cmd: terraform validate silent: true tf:fmt: desc: Format Terraform configuration files cmd: terraform fmt -recursive silent: true tf:plan: desc: Create execution plan from the Terraform configuration cmd: terraform plan -out=plan.out silent: true tf:apply: desc: Apply Terraform configuration cmds: - defer: | rm plan.out rm -f modules/jenkins/jcasc/clouds.ecs.yaml - task: tf:plan - terraform apply plan.out silent: true tf:destroy: desc: Destroy Terraform configuration cmd: terraform destroy -auto-approve silent: true