Skip to content
Permalink
main
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2.1
orbs:
buildevents: honeycombio/buildevents@0.2.7
kubernetes: circleci/kubernetes@1.3.0
executors:
linuxgo:
docker:
- image: golang:1
commands:
go-build:
steps:
## method 1 to send a command span
## the raw buildevents binary is available in the $PATH but requires more arguments
## don't use CGO so that this binary can run in alpine-linux containers
- run: |
GOOS=linux \
GOARCH=amd64 \
CGO_ENABLED=0 \
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID go_build -- \
go build -i -ldflags "-X main.Version=${MAJOR}.${MINOR}.${BUILD_NUMBER} -X main.Branch=${CIRCLE_BRANCH} -X main.Hash=${CIRCLE_SHA1}" \
-o $GOPATH/bin \
./...
jobs:
setup:
executor: linuxgo
steps:
- buildevents/start_trace
watch:
executor: linuxgo
steps:
- buildevents/watch_build_and_finish
test:
executor: linuxgo
steps:
- buildevents/with_job_span:
steps:
- checkout
## method 2 to send a command span
## buildevent/berun is a circleci friendly way to create a buildevents command span
- buildevents/berun:
bename: go_test
becommand: go test -v ./...
build:
executor: linuxgo
environment:
BUILD_NUMBER: <<pipeline.number>>
steps:
- buildevents/with_job_span:
steps:
- checkout
- run: buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID go_mod_downlaod -- go mod download
- go-build:
- run: mkdir -v artifacts; cp -v $GOPATH/bin/go-discord-bot artifacts/
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID bicep_install -- \
curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64 && \
chmod +x ./bicep && \
mv ./bicep /usr/local/bin/bicep
- run: |
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID bicep_build -- \
bicep build deploy.bicep --outfile artifacts/deploy.json
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID update_pod_version -- \
sed -i "s/{{ContainerVersion}}/$MAJOR.$MINOR.$BUILD_NUMBER/g" deploy.yml \
&& cp deploy.yml artifacts/deploy.yml
- run: echo "size=$(du -sb artifacts | cut -f 1)" >> $BASH_ENV
- buildevents/add_context:
field_name: artifacts_size_bytes
field_value: $size
- buildevents/add_context:
field_name: build_version
field_value: $MAJOR.$MINOR.$BUILD_NUMBER
- store_artifacts:
path: artifacts/
- persist_to_workspace:
# Must be an absolute path, or relative path from working_directory. This is a directory on the container which is
# taken to be the root directory of the workspace.
root: artifacts
# Must be relative path from root
paths:
- go-discord-bot
- deploy.json
- deploy.yml
publish:
machine:
image: ubuntu-2004:202201-02
environment:
BUILD_NUMBER: <<pipeline.number>>
steps:
- buildevents/with_job_span:
steps:
- checkout
- attach_workspace:
# Must be absolute path or relative path from working_directory
at: artifacts
- run: echo "$ACR_PASSWORD" | docker login halbarad.azurecr.io -u $ACR_USER --password-stdin
- run: echo "export SHORT_SHA=$(echo $CIRCLE_SHA1 | head -c 8)" >> $BASH_ENV
# build the docker container
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID docker_build -- \
docker build . -t halbarad.azurecr.io/go/discord-bot:$SHORT_SHA \
-t halbarad.azurecr.io/go/discord-bot:$MAJOR.$MINOR.$BUILD_NUMBER
## push the docker container to ACR
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID docker_push -- \
docker push halbarad.azurecr.io/go/discord-bot:$SHORT_SHA && \
docker push halbarad.azurecr.io/go/discord-bot:$MAJOR.$MINOR.$BUILD_NUMBER
- buildevents/add_context:
field_name: container_version
field_value: $MAJOR.$MINOR.$BUILD_NUMBER
deploy:
docker:
- image: mcr.microsoft.com/azure-cli:2.20.0
environment:
BUILD_NUMBER: <<pipeline.number>>
steps:
- buildevents/with_job_span:
steps:
- attach_workspace:
# Must be absolute path or relative path from working_directory
at: artifacts
- kubernetes/install-kubectl
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID az_login -- \
az login --service-principal -u $AZ_SP_UUID -p $AZ_SP_PASS --tenant $AZ_SP_TENANT
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID az_infra_update -- \
az deployment group create --resource-group $AZ_RG --template-file artifacts/deploy.json \
--name $MAJOR.$MINOR.$BUILD_NUMBER --parameters containerName=$AZ_ACI
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID az_kube_connection -- \
az aks get-credentials --resource-group $AKS_RG --name $AKS_NAME
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID kube_config_update -- \
kubectl apply -f artifacts/deploy.yml
- run: |
DATE=$(date +%s)
curl https://api.honeycomb.io/1/markers/$HONEYCOMB_DATASET -X POST \
-H "X-Honeycomb-Team: $MARKER_API_KEY" \
-d '{"message":"deploy '$MAJOR'.'$MINOR'.'$BUILD_NUMBER'", "type":"deploy", "start_time":'$DATE'}'
featureflags:
docker:
- image: mcr.microsoft.com/powershell:latest
environment:
BUILD_NUMBER: <<pipeline.number>>
steps:
- buildevents/with_job_span:
steps:
- checkout
# push new flags into Optimizely
- run: |
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID publish_feature_flags -- \
pwsh -File Update-FeatureFlags.ps1 -ApiKey $OPTIMIZELY_TOKEN -Path flags.json
workflows:
build:
jobs:
- setup:
filters:
tags:
only: /.*/
- watch:
requires:
- setup
filters:
tags:
only: /.*/
- test:
requires:
- setup
filters:
tags:
only: /.*/
- build:
requires:
- setup
filters:
tags:
only: /.*/
- publish:
requires:
- build
filters:
branches:
only: main
- featureflags:
requires:
- build
filters:
branches:
only: main
- deploy:
requires:
- publish
filters:
branches:
only: main