Skip to content

Commit

Permalink
migrate watchman from forge repo to its own repo
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino committed Sep 14, 2020
1 parent 91e848c commit 9b5ea7b
Show file tree
Hide file tree
Showing 228 changed files with 19,847 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
watchman-*.tar
72 changes: 72 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
version: v1.0
name: watchman
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
blocks:
- name: test
dependencies: []
task:
secrets:
- name: gcp-test
jobs:
- name: Test
commands:
- checkout
- echo $GOOGLE_APPLICATION_CREDENTIALS > key.json
- export GOOGLE_APPLICATION_CREDENTIALS="$(pwd)/key.json"
- sem-version elixir 1.9.0
- make testup
- mix local.hex --force
- mix local.rebar --force

- cache restore mix-deps2-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock),mix-deps2-$SEMAPHORE_GIT_BRANCH,mix-deps2-master
- cache restore mix-build2-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock),mix-build2-$SEMAPHORE_GIT_BRANCH,mix-build2-master

- mix deps.get
- mix test

- cache store mix-deps2-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock) deps
- cache store mix-build2-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock) _build
- cache store mix-deps2-$SEMAPHORE_GIT_BRANCH deps
- cache store mix-build2-$SEMAPHORE_GIT_BRANCH _build
- name: build
dependencies: ['test']
skip:
when: "branch != 'master'"
task:
secrets:
- name: GCP
- name: gcp-test
- name: forge
prologue:
commands:
# Authenticate using the file injected from the secret
- gcloud auth activate-service-account --key-file=.secrets/gcp-piazzaapp.json
# Don't forget -q to silence confirmation prompts
- gcloud auth configure-docker -q
- docker login -u mguarino46@gmail.com -p $FORGE_ACCESS_TOKEN dkr.piazza.app
- checkout
jobs:
- name: "Build watchman"
commands:
- make build
- make push
# - name: deploy
# dependencies: ['build']
# skip:
# when: "branch != 'master'"
# task:
# secrets:
# - name: forge
# prologue:
# commands:
# - checkout
# - wget -O forge.cmd https://storage.googleapis.com/forge-assets/uploads/artifacts/c3e93e69-7bb3-4d7b-a3e7-01b93abf10b4/forge?v=63751273416
# - chmod +x ./forge.cmd
# jobs:
# - name: "Deploy with watchman"
# commands:
# - export GIT_COMMIT_MESSAGE=$(git log -1 --pretty=%B | cat | head -n 1)
# - ./forge.cmd webhook watchman "${GIT_COMMIT_MESSAGE}" --secret "${FORGE_WEBHOOK_SECRET}" --url https://watchman.piazza.app/v1/webhook
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
erlang 22.0.7
elixir 1.9.0
146 changes: 146 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# The version of Alpine to use for the final image
# This should match the version of Alpine that the `elixir:1.7.2-alpine` image uses
ARG ALPINE_VERSION=3.8

FROM elixir:1.9-alpine AS builder

# The following are build arguments used to change variable parts of the image.
# The name of your application/release (required)
ARG APP_NAME
# The version of the application we are building (required)
ARG APP_VSN
# The environment to build with
ARG MIX_ENV=prod
# Set this to true if this release is not a Phoenix app
ARG SKIP_PHOENIX=false
# If you are using an umbrella project, you can change this
# argument to the directory the Phoenix app is in so that the assets
# can be built
ARG PHOENIX_SUBDIR=apps/watchman

ENV SKIP_PHOENIX=${SKIP_PHOENIX} \
APP_NAME=${APP_NAME} \
APP_VSN=${APP_VSN} \
MIX_ENV=${MIX_ENV}

# By convention, /opt is typically used for applications
WORKDIR /opt/app

# This step installs all the build tools we'll need
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
nodejs \
yarn \
git \
build-base && \
mix local.rebar --force && \
mix local.hex --force

# This copies our app source code into the build container
COPY . .

RUN mix do deps.get, compile

# This step builds assets for the Phoenix app (if there is one)
# If you aren't building a Phoenix app, pass `--build-arg SKIP_PHOENIX=true`
# This is mostly here for demonstration purposes
RUN if [ ! "$SKIP_PHOENIX" = "true" ]; then \
cd ${PHOENIX_SUBDIR}/assets && \
yarn install && \
yarn run build; \
fi

RUN \
mkdir -p /opt/built && \
mix distillery.release --name ${APP_NAME} && \
cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/${APP_VSN}/${APP_NAME}.tar.gz /opt/built && \
cd /opt/built && \
tar -xzf ${APP_NAME}.tar.gz && \
rm ${APP_NAME}.tar.gz

FROM golang:alpine AS cmd

RUN apk update && apk add --no-cache git

WORKDIR $GOPATH/src/mypackage/myapp/
COPY cmd/ .
RUN ls -al
RUN go build -o /go/bin/forge

FROM alpine:3 as helm

ARG VERSION=3.3.1
ENV TERRAFORM_VERSION=0.12.18

# ENV BASE_URL="https://storage.googleapis.com/kubernetes-helm"
ENV BASE_URL="https://get.helm.sh"
ENV TAR_FILE="helm-v${VERSION}-linux-amd64.tar.gz"

RUN apk add --update --no-cache curl ca-certificates unzip wget openssl && \
curl -L ${BASE_URL}/${TAR_FILE} | tar xvz && \
mv linux-amd64/helm /usr/local/bin/helm && \
wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/local/bin && \
chmod +x /usr/local/bin/helm && \
chmod +x /usr/local/bin/terraform

FROM docker:17.12.0-ce as static-docker-source

# From this line onwards, we're in a new image, which will be the image used in production
FROM erlang:22-alpine

ARG CLOUD_SDK_VERSION=273.0.0
ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION
ENV PATH /google-cloud-sdk/bin:$PATH

COPY --from=static-docker-source /usr/local/bin/docker /usr/local/bin/docker
COPY --from=cmd /go/bin/forge /usr/local/bin/forge
COPY --from=helm /usr/local/bin/helm /usr/local/bin/helm
COPY --from=helm /usr/local/bin/terraform /usr/local/bin/terraform

RUN apk --no-cache add \
curl \
python \
py-crcmod \
bash \
libc6-compat \
openssh-client \
git \
gnupg \
&& curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz && \
tar xzf google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz && \
rm google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz && \
gcloud config set core/disable_usage_reporting true && \
gcloud config set component_manager/disable_update_check true && \
gcloud config set metrics/environment github_docker_image && \
gcloud --version

# The name of your application/release (required)
ARG APP_NAME
ARG KUBECTL_VERSION='1.16.14'
ADD https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl /usr/local/bin/kubectl

RUN set -x && \
apk add --no-cache curl openssl-dev ca-certificates bash && \
chmod +x /usr/local/bin/kubectl && \
kubectl version --client

ENV REPLACE_OS_VARS=true \
APP_NAME=${APP_NAME}

WORKDIR /opt/app

RUN helm plugin install https://github.com/chartmuseum/helm-push
RUN mkdir -p /root/.ssh
RUN chmod 0700 /root/.ssh
RUN mkdir -p /root/.forge
RUN mkdir -p /root/.creds

# add common repos to known hosts
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts

COPY --from=builder /opt/built .

CMD trap 'exit' INT; eval $(ssh-agent -s); /opt/app/bin/${APP_NAME} foreground
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.PHONY: help

GCP_PROJECT ?= piazzaapp
APP_NAME ?= watchman
APP_VSN ?= `cat VERSION`
BUILD ?= `git rev-parse --short HEAD`
DKR_HOST ?= dkr.piazza.app

help:
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

build: ## Build the Docker image
docker build --build-arg APP_NAME=$(APP_NAME) \
--build-arg APP_VSN=$(APP_VSN) \
-t $(APP_NAME):$(APP_VSN) \
-t $(APP_NAME):latest \
-t gcr.io/$(GCP_PROJECT)/$(APP_NAME):$(APP_VSN) \
-t $(DKR_HOST)/watchman/$(APP_NAME):$(APP_VSN) .

push: ## push to gcr
docker push gcr.io/$(GCP_PROJECT)/$(APP_NAME):$(APP_VSN)
docker push $(DKR_HOST)/watchman/${APP_NAME}:$(APP_VSN)

testup: ## sets up dependent services for test
docker-compose up -d

testdown: ## tear down test dependencies
docker-compose down

connectdb: ## proxies the db in kubernetes via kubectl
@echo "run psql -U forge -h 127.0.0.1 forge to connect"
kubectl port-forward statefulset/watchman-postgresql 5432 -n watchman

web: ## starts a local webserver
cd assets && yarn start
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# watchman
forge admin console
# Watchman

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `watchman` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:watchman, "~> 0.1.0"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/watchman](https://hexdocs.pm/watchman).

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
23 changes: 23 additions & 0 deletions assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
Loading

0 comments on commit 9b5ea7b

Please sign in to comment.