Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Initial CircleCI support (WIP) #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
version: 2.1

orbs:
aws-cli: circleci/[email protected]

executors:
golang:
docker:
- image: circleci/golang:1.12
environment:
- GOOS: linux
- GOARCH: amd64
nodejs:
docker:
- image: circleci/node:10

commands:


jobs:
build-golang:
executor: golang
steps:
- checkout
- restore_cache:
keys:
- go-{{ checksum "go.sum" }}
- run: go mod download
- save_cache:
key: go-{{ checksum "go.sum" }}
paths:
- /go/pkg/mod

- run:
command: |
mkdir -p ./artifacts
BUILDDIR=$(mktemp -d)
trap "rm -r ${BUILDDIR}" EXIT

for CMD in ./cmd/*; do
[ -e "${CMD}/main.go" ] || continue
CMD_BASE=$(basename ${CMD})
BINARY_NAME=${CMD_BASE/#lambda-/vpn-}

go build -ldflags="-w -s" -o ${BUILDDIR}/${BINARY_NAME} ${CMD}
zip -j ./artifacts/${BINARY_NAME}.zip ${BUILDDIR}/${BINARY_NAME}
done

- persist_to_workspace:
root: ./artifacts
paths:
- ./*.zip
- store_artifacts:
path: ./artifacts

build-frontend:
executor: nodejs
steps:
- checkout
- restore_cache:
keys:
- node-{{ checksum "frontend/package.json" }}
- run: npm --prefix ./frontend install
- save_cache:
key: node-{{ checksum "frontend/package.json" }}
paths:
- frontend/node_modules

- run:
name: "Build Frontend Application"
command: |
npm --prefix ./frontend run build
mkdir -p ./artifacts
tar -czvf ./artifacts/frontend.tar.gz -C ./frontend/dist .

- persist_to_workspace:
root: ./artifacts
paths:
- frontend.tar.gz
- store_artifacts:
path: ./artifacts

deploy:
executor: aws-cli/default
steps:
- aws-cli/install
- aws-cli/configure
- run: aws sts get-caller-identity

- attach_workspace:
at: ./artifacts
- run: ls -lah ./artifacts


publish-github-release:
docker:
- image: cibuilds/github:0.12
steps:
- attach_workspace:
at: ./artifacts
- run:
name: "Publish Release on GitHub"
command: |
ghr -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${CIRCLE_TAG} ./artifacts/


workflows:
version: 2.1

build:
jobs:
- build-golang:
filters:
tags:
only: /.*/
- build-frontend:
filters:
tags:
only: /.*/
- publish-github-release:
context: gh-releases
requires:
- build-golang
- build-frontend
filters:
branches:
ignore: /.*/
tags:
only: /^v\d+\.\d+\.\d+$/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/artifacts/
.idea/
.DS_Store
46 changes: 46 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

set -eu

BUILDDIR=$(mktemp -d)
trap 'rm -r ${BUILDDIR}' EXIT

ARTIFACTSDIR=./artifacts
mkdir -p "${ARTIFACTSDIR}"

build_lambdas() {
for CMD in ./cmd/*; do
[ -e "${CMD}/main.go" ] || continue
CMD_BASE=$(basename "${CMD}")
BINARY_NAME=${CMD_BASE/#lambda-/vpn-}

go build -o "${BUILDDIR}/${BINARY_NAME}" "${CMD}"
zip -j "${ARTIFACTSDIR}/${BINARY_NAME}.zip" "${BUILDDIR}/${BINARY_NAME}"
done
}

build_frontend() {
npm --prefix ./frontend install
npm --prefix ./frontend run build
tar -czf ./artifacts/frontend.tar.gz -C ./frontend/dist .
}

build_all() {
build_lambdas
build_frontend
}

case $1 in
lambdas)
build_lambdas
;;
frontend)
build_frontend
;;
all)
build_all
;;
*)
printf "Unknown command %s\n" "$1"
;;
esac
40 changes: 17 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
module github.com/empathybroker/aws-vpn

go 1.12

require (
cloud.google.com/go v0.36.0 // indirect
github.com/DATA-DOG/go-sqlmock v1.3.3 // indirect
github.com/aws/aws-lambda-go v1.9.0
github.com/aws/aws-sdk-go v1.17.12
github.com/aws/aws-xray-sdk-go v1.0.0-rc.9.0.20190219213013-12231bd5f588
github.com/awslabs/aws-lambda-go-api-proxy v0.2.0
github.com/coreos/go-systemd v0.0.0-20190212144455-93d5ec2c7f76
github.com/aws/aws-lambda-go v1.12.0
github.com/aws/aws-sdk-go v1.22.0
github.com/aws/aws-xray-sdk-go v0.9.4
github.com/awslabs/aws-lambda-go-api-proxy v0.4.1
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f
github.com/godbus/dbus v0.0.0-20181101234600-2ff6f7ffd60f // indirect
github.com/golang/protobuf v1.3.0 // indirect
github.com/google/uuid v1.1.1
github.com/gorilla/mux v1.7.0
github.com/kelseyhightower/envconfig v1.3.0
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/google/uuid v0.0.0-20171129191014-dec09d789f3d
github.com/gorilla/mux v1.7.3
github.com/kelseyhightower/envconfig v1.4.0
github.com/kr/pretty v0.1.0 // indirect
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.3.0
github.com/stretchr/testify v1.3.0 // indirect
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25 // indirect
golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 // indirect
golang.org/x/sys v0.0.0-20190306220723-b294cbcfc56d // indirect
google.golang.org/api v0.1.0
github.com/sirupsen/logrus v1.4.2
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
google.golang.org/api v0.7.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/square/go-jose.v2 v2.3.0
gopkg.in/yaml.v2 v2.2.2 // indirect
gopkg.in/square/go-jose.v2 v2.3.1
)
Loading