asg-server/bitbucket-pipelines.yml
Aleksandr Soloshenko ac51280a2b Added: ttl support
2023-10-29 20:13:03 +07:00

82 lines
2.4 KiB
YAML

image: atlassian/default-image:3
definitions:
caches:
gomodules: ~/.cache/go-build
steps:
- step: &docker-lint
runs-on:
- self.hosted
- linux
name: Lint the Dockerfile
image: hadolint/hadolint:latest-debian
script:
- hadolint build/package/Dockerfile*
- step: &unit-tests
runs-on:
- self.hosted
- linux
name: Run unit tests
image: golang:1.20
caches:
- gomodules
script:
- echo '[url "ssh://git@bitbucket.org/"]' >> ~/.gitconfig
- echo ' insteadOf = https://bitbucket.org/' >> ~/.gitconfig
- go env -w GOPRIVATE="bitbucket.org/soft-c/*"
- go test ./...
- step: &build-docker
runs-on:
- self.hosted
- linux
name: Build and push Docker image
services:
- docker
caches:
- docker
script:
- docker version
- echo ${DOCKER_PASSWORD} | docker login ${DOCKER_CR} --username "$DOCKER_USERNAME" --password-stdin
- export SSH_PRV_KEY="$(cat /opt/atlassian/pipelines/agent/ssh/id_rsa)"
- chmod +x ./scripts/docker-build.sh && ./scripts/docker-build.sh
- step: &deploy
runs-on:
- self.hosted
- linux
name: Deploy to Docker Swarm
image: hashicorp/terraform:1.4
deployment: production
script:
- terraform -chdir=./deployments/docker-swarm-terraform init
- |
terraform -chdir=./deployments/docker-swarm-terraform apply -auto-approve -input=false \
-var "swarm-manager-host=${SWARM_MANAGER_HOST}" \
-var "registry-password=${DOCKER_PASSWORD}" \
-var "app-name=${APP_NAME}" \
-var "app-version=${BITBUCKET_TAG#v}" \
-var "app-host=${APP_HOST}" \
-var "app-config-b64=${APP_CONFIG_B64}" \
-var "app-env-json-b64=${APP_ENV_JSON_B64}"
pipelines:
default:
- parallel:
- step: *docker-lint
- step: *unit-tests
- step: *build-docker
branches:
testing:
- parallel:
- step: *docker-lint
- step: *unit-tests
- step: *build-docker
master:
- parallel:
- step: *docker-lint
- step: *unit-tests
- step: *build-docker
tags:
v*:
- step: *build-docker
- step: *deploy