Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
update: deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
sysatom committed May 28, 2021
1 parent a7e648c commit 82d2758
Show file tree
Hide file tree
Showing 22 changed files with 408 additions and 16 deletions.
133 changes: 133 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: docker

on:
push:
tags:
- '*'
branches:
- '*'
pull_request:

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16

- name: Get dependencies
run: go get -v -t -d ./...

- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
install-only: true

- name: Build
run: make build

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push cron
uses: docker/build-push-action@v2
with:
context: .
push: true
file: build/cron/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/cron:${{ github.sha }}

- name: Build and push gateway
uses: docker/build-push-action@v2
with:
context: .
push: true
file: build/gateway/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/gateway:${{ github.sha }}

- name: Build and push message
uses: docker/build-push-action@v2
with:
context: .
push: true
file: build/message/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/message:${{ github.sha }}

- name: Build and push middle
uses: docker/build-push-action@v2
with:
context: .
push: true
file: build/middle/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/middle:${{ github.sha }}

- name: Build and push spider
uses: docker/build-push-action@v2
with:
context: .
push: true
file: build/spider/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/spider:${{ github.sha }}

- name: Build and push storage
uses: docker/build-push-action@v2
with:
context: .
push: true
file: build/storage/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/storage:${{ github.sha }}

- name: Build and push subscribe
uses: docker/build-push-action@v2
with:
context: .
push: true
file: build/subscribe/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/subscribe:${{ github.sha }}

- name: Build and push task
uses: docker/build-push-action@v2
with:
context: .
push: true
file: build/task/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/task:${{ github.sha }}

- name: Build and push web
uses: docker/build-push-action@v2
with:
context: .
push: true
file: build/web/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/web:${{ github.sha }}

- name: Build and push worker
uses: docker/build-push-action@v2
with:
context: .
push: true
file: build/worker/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/worker:${{ github.sha }}

- name: Build and push workflow
uses: docker/build-push-action@v2
with:
context: .
push: true
file: build/workflow/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/workflow:${{ github.sha }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ configs/influxdb/
configs/*.conf
internal/app/web/templates/
*.db
deployments/tmp/
deployments/docker-compose/tmp
deployments/docker-compose/.env
upload/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apps = 'gateway' 'web' 'message' 'subscribe' 'middle' 'workflow' 'task' 'spider' 'cron' 'worker'
apps = 'gateway' 'web' 'message' 'subscribe' 'middle' 'workflow' 'task' 'spider' 'cron' 'worker' 'storage'
agents = 'server' 'redis'

.PHONY: build
Expand Down
4 changes: 2 additions & 2 deletions build/cron/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM alpine:latest

RUN apk update && apk add bash

ADD ./dist/cron-linux-amd64 app
ADD ./configs/cron.yml .
ADD ./dist/cron-linux-amd64/cron app
CMD ["./app"]
4 changes: 2 additions & 2 deletions build/gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM alpine:latest

RUN apk update && apk add bash

ADD ./dist/gateway-linux-amd64 app
ADD ./configs/gateway.yml .
COPY ./dist/gateway_linux_amd64/gateway app
CMD ["./app"]
4 changes: 2 additions & 2 deletions build/message/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM alpine:latest

RUN apk update && apk add bash

ADD ./dist/message-linux-amd64 app
ADD ./configs/message.yml .
ADD ./dist/message-linux-amd64/message app
CMD ["./app"]
4 changes: 2 additions & 2 deletions build/middle/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM alpine:latest

RUN apk update && apk add bash

ADD ./dist/middle-linux-amd64 app
ADD ./configs/middle.yml .
ADD ./dist/middle-linux-amd64/middle app
CMD ["./app"]
4 changes: 2 additions & 2 deletions build/spider/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM alpine:latest

RUN apk update && apk add bash

ADD ./dist/spider-linux-amd64 app
ADD ./configs/spider.yml .
ADD ./dist/spider-linux-amd64/spider app
CMD ["./app"]
6 changes: 6 additions & 0 deletions build/storage/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM alpine:latest

RUN apk update && apk add bash

ADD ./dist/storage-linux-amd64/storage app
CMD ["./app"]
4 changes: 2 additions & 2 deletions build/subscribe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM alpine:latest

RUN apk update && apk add bash

ADD ./dist/subscribe-linux-amd64 app
ADD ./configs/subscribe.yml .
ADD ./dist/subscribe-linux-amd64/subscribe app
CMD ["./app"]
6 changes: 6 additions & 0 deletions build/task/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM alpine:latest

RUN apk update && apk add bash

ADD ./dist/task-linux-amd64/task app
CMD ["./app"]
4 changes: 2 additions & 2 deletions build/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM alpine:latest

RUN apk update && apk add bash

ADD ./dist/web-linux-amd64 app
ADD ./configs/web.yml .
ADD ./dist/web-linux-amd64/web app
CMD ["./app"]
6 changes: 6 additions & 0 deletions build/worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM alpine:latest

RUN apk update && apk add bash

ADD ./dist/worker-linux-amd64/worker app
CMD ["./app"]
6 changes: 6 additions & 0 deletions build/workflow/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM alpine:latest

RUN apk update && apk add bash

ADD ./dist/workflow-linux-amd64/workflow app
CMD ["./app"]
4 changes: 4 additions & 0 deletions deployments/docker-compose/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Docker image version
GITHUB_VERSION=
# config center url
XCONF_URL=
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,25 @@ services:
- "9411:9411"
environment:
- COLLECTOR_ZIPKIN_HOST_PORT=:9411

xconf:
image: xuxu123/xconf-all:latest
environment:
BROADCAST: broker
DATABASE_URL: root:123456@(mysql:3306)/xconf?charset=utf8&parseTime=true&loc=Local
ports:
- "8080:8080"
depends_on:
- mysql

gateway:
image: tsundata/gateway:${APP_VERSION}
restart: always
environment:
XCONF_URL: ${XCONF_URL}
XCONF_CLUSTER: dev
XCONF_NAMESPACE: gateway
ports:
- "7000:7000"
depends_on:
- xconf
55 changes: 55 additions & 0 deletions deployments/kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Kubernetes deployment

# Install XConf

## 1. Deployment

Deploy assistant to your Kubernetes Cluster from zero.

### Create a namespace

Create a namespace in the cluster to manage all the resources of Xconf. Edit `namespace.yaml` if you need.

```kubectl create namespace.yaml```

### Edit config files

- [ALL Files] Replace `$MICRO_REGISTRY_ADDRESS` to your cluser etcd address or your own etcd service address.
- [ALL Files] Check the version of image, change if you want.
- [config-srv.yaml] Replace `$DATABASE_URL` to your own MySQL database url.
- Change other fields if you know what you are doing.

### Create Kubernets resources

```
kubectl create -f micro.yaml
kubectl create -f config-srv.yaml
kubectl create -f agent-api.yaml
kubectl create -f admin-api.yaml
```

### Access Admin UI

By default the micro-api will be exposed by LoadBalancer, check service `micro` under namespace `xconf` for detail.

`kubectl describe --namespace xconf service micro`

You will find the Ingress address and the port.

Use url `http://addr:port/admin/ui/` to access the admin UI.

## 2. Update

Update the Kubernets configuration if resources have already existed.

Modify the config file corresponding to you needs.

Apply the update:

```kubectl apply -f FILENAME```

## 3. Remove

You can remove all the deployments by deleting the whole namespace.

```kubectl delete namespace xconf```
33 changes: 33 additions & 0 deletions deployments/kubernetes/xconf/admin-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
kind: Deployment
apiVersion: apps/v1
metadata:
name: admin-api
namespace: xconf
spec:
replicas: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
selector:
matchLabels:
app: admin-api
template:
metadata:
labels:
app: admin-api
spec:
containers:
- name: admin-api
image: 'xuxu123/admin-api:v0.1.3'
imagePullPolicy: Always
env:
- name: MICRO_SERVER_ADDRESS
value: 0.0.0.0:8080
- name: MICRO_REGISTRY
value: "etcd"
- name: MICRO_REGISTRY_ADDRESS
value: $MICRO_REGISTRY_ADDRESS
ports:
- containerPort: 8080
35 changes: 35 additions & 0 deletions deployments/kubernetes/xconf/agent-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
kind: Deployment
apiVersion: apps/v1
metadata:
name: agent-api
namespace: xconf
spec:
replicas: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
selector:
matchLabels:
app: agent-api
template:
metadata:
labels:
app: agent-api
spec:
containers:
- name: agent-api
image: 'xuxu123/agent-api:v0.1.3'
imagePullPolicy: Always
env:
- name: MICRO_SERVER_ADDRESS
value: 0.0.0.0:8080
- name: XCONF_CACHE_SIZE
value: "1048576"
- name: MICRO_REGISTRY
value: "etcd"
- name: MICRO_REGISTRY_ADDRESS
value: $MICRO_REGISTRY_ADDRESS
ports:
- containerPort: 8080
Loading

0 comments on commit 82d2758

Please sign in to comment.