Skip to content

Commit 6e23344

Browse files
committed
Added Dockerfile and CI manifests to automate release
1 parent d97f2ba commit 6e23344

File tree

6 files changed

+306
-1
lines changed

6 files changed

+306
-1
lines changed

.github/workflows/master.yml

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,69 @@ jobs:
4747
uses: sonarsource/sonarcloud-github-action@v3.0.0
4848
env:
4949
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
50+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
51+
52+
docker:
53+
name: Publish Docker Image
54+
needs: [ build-test ]
55+
runs-on: ubuntu-latest
56+
if: success() && github.ref == 'refs/heads/master'
57+
58+
outputs:
59+
digest: ${{ steps.docker_build.outputs.digest }}
60+
61+
steps:
62+
- name: Set up QEMU
63+
uses: docker/setup-qemu-action@v3
64+
65+
- name: Set up Docker Buildx
66+
uses: docker/setup-buildx-action@v3
67+
68+
- name: Login to DockerHub
69+
uses: docker/login-action@v3
70+
with:
71+
username: ${{ secrets.DOCKERHUB_USERNAME }}
72+
password: ${{ secrets.DOCKERHUB_TOKEN }}
73+
74+
- name: Build and push
75+
id: docker_build
76+
uses: docker/build-push-action@v6
77+
with:
78+
push: true
79+
platforms: linux/amd64,linux/arm64
80+
tags: trackerforce/switcher-gitops:latest
81+
82+
update-kustomize:
83+
name: Deploy
84+
needs: [ docker ]
85+
runs-on: ubuntu-latest
86+
87+
steps:
88+
- name: Checkout
89+
uses: actions/checkout@v4
90+
with:
91+
ref: 'master'
92+
93+
- name: Checkout Kustomize
94+
uses: actions/checkout@v4
95+
with:
96+
token: ${{ secrets.ARGOCD_PAT }}
97+
repository: switcherapi/switcher-deployment
98+
ref: master
99+
100+
- name: Set up arkade-get
101+
uses: alexellis/arkade-get@master
102+
with:
103+
kubectl: latest
104+
kustomize: latest
105+
106+
- name: Update GitOps repository
107+
run: |
108+
cd switcher-gitops/base
109+
echo RELEASE_TIME=`date` > environment-properties.env
110+
kustomize edit set image trackerforce/switcher-gitops:latest=trackerforce/switcher-gitops@${{ needs.docker.outputs.digest }}
111+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
112+
git config --global user.name "${{ github.actor }}"
113+
git add .
114+
git commit -m "[argocd] switcher-gitops: ${{ needs.docker.outputs.digest }}"
115+
git push

.github/workflows/re-release.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Re-release CI
2+
run-name: Re-releasing - ${{ github.event.inputs.tag }} by @${{ github.actor }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
tag:
8+
description: 'Tag'
9+
required: true
10+
11+
jobs:
12+
build-test:
13+
name: Build & Test
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Git checkout
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
ref: ${{ github.event.inputs.tag }}
22+
23+
- name: Set up Go 1.23.0
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: '1.23.0'
27+
28+
- name: Start MongoDB
29+
uses: supercharge/mongodb-github-action@1.11.0
30+
with:
31+
mongodb-version: 7.0
32+
33+
- name: Build
34+
run: go build -v ./...
35+
36+
- name: Test
37+
run: go test -p 1 -v ./... -coverprofile="coverage.out"
38+
env:
39+
GO_ENV: test
40+
MONGODB_URI: mongodb://127.0.0.1:27017
41+
MONGO_DB: switcher-gitops-test
42+
GIT_TOKEN_PRIVATE_KEY: ${{ secrets.GIT_TOKEN_PRIVATE_KEY }}
43+
GIT_USER: ${{ secrets.GIT_USER }}
44+
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
45+
GIT_TOKEN_READ_ONLY: ${{ secrets.GIT_TOKEN_READ_ONLY }}
46+
GIT_REPO_URL: ${{ secrets.GIT_REPO_URL }}
47+
GIT_BRANCH: ${{ secrets.GIT_BRANCH }}
48+
49+
docker:
50+
name: Publish Docker Image
51+
needs: [ build-test ]
52+
runs-on: ubuntu-latest
53+
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
with:
58+
fetch-depth: 0
59+
ref: ${{ github.event.inputs.tag }}
60+
61+
- name: Docker meta
62+
id: meta
63+
uses: docker/metadata-action@v5
64+
with:
65+
images: trackerforce/switcher-gitops
66+
tags: ${{ github.event.inputs.tag }}
67+
68+
- name: Set up QEMU
69+
uses: docker/setup-qemu-action@v3
70+
71+
- name: Set up Docker Buildx
72+
uses: docker/setup-buildx-action@v3
73+
74+
- name: Login to DockerHub
75+
uses: docker/login-action@v3
76+
with:
77+
username: ${{ secrets.DOCKERHUB_USERNAME }}
78+
password: ${{ secrets.DOCKERHUB_TOKEN }}
79+
80+
- name: Build and push
81+
uses: docker/build-push-action@v6
82+
with:
83+
context: .
84+
push: true
85+
platforms: linux/amd64,linux/arm64
86+
tags: ${{ steps.meta.outputs.tags }}
87+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/release.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Release CI
2+
3+
on:
4+
release:
5+
types: [ created ]
6+
7+
jobs:
8+
build-test:
9+
name: Build & Test
10+
runs-on: ubuntu-latest
11+
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Set up Go 1.23.0
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: '1.23.0'
22+
23+
- name: Start MongoDB
24+
uses: supercharge/mongodb-github-action@1.11.0
25+
with:
26+
mongodb-version: 7.0
27+
28+
- name: Build
29+
run: go build -v ./...
30+
31+
- name: Test
32+
run: go test -p 1 -v ./... -coverprofile="coverage.out"
33+
env:
34+
GO_ENV: test
35+
MONGODB_URI: mongodb://127.0.0.1:27017
36+
MONGO_DB: switcher-gitops-test
37+
GIT_TOKEN_PRIVATE_KEY: ${{ secrets.GIT_TOKEN_PRIVATE_KEY }}
38+
GIT_USER: ${{ secrets.GIT_USER }}
39+
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
40+
GIT_TOKEN_READ_ONLY: ${{ secrets.GIT_TOKEN_READ_ONLY }}
41+
GIT_REPO_URL: ${{ secrets.GIT_REPO_URL }}
42+
GIT_BRANCH: ${{ secrets.GIT_BRANCH }}
43+
44+
docker:
45+
name: Publish Docker Image
46+
needs: [ build-test ]
47+
runs-on: ubuntu-latest
48+
49+
steps:
50+
- name: Checkout code
51+
uses: actions/checkout@v4
52+
53+
- name: Docker meta
54+
id: meta
55+
uses: docker/metadata-action@v5
56+
with:
57+
images: trackerforce/switcher-gitops
58+
59+
- name: Set up QEMU
60+
uses: docker/setup-qemu-action@v3
61+
62+
- name: Set up Docker Buildx
63+
uses: docker/setup-buildx-action@v3
64+
65+
- name: Login to DockerHub
66+
uses: docker/login-action@v3
67+
with:
68+
username: ${{ secrets.DOCKERHUB_USERNAME }}
69+
password: ${{ secrets.DOCKERHUB_TOKEN }}
70+
71+
- name: Build and push
72+
uses: docker/build-push-action@v6
73+
with:
74+
context: .
75+
push: true
76+
platforms: linux/amd64,linux/arm64
77+
tags: ${{ steps.meta.outputs.tags }}
78+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM golang:1.23.1-alpine AS builder
2+
3+
WORKDIR /app
4+
COPY . .
5+
6+
RUN go mod download && \
7+
go mod verify && \
8+
CGO_ENABLED=0 go build -o ./bin/app ./src/cmd/app/main.go
9+
10+
FROM gcr.io/distroless/static-debian12:nonroot
11+
12+
COPY --from=builder /app/bin/app /app

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ GitOps Domain Snapshot Orchestrator for Switcher API
2727
- Flexible settings allow to define the best workflow for your organization
2828
- Orquestrates accounts per Domain environments allowing seemless integration with any branching strategy
2929

30+
# Deploying locally
31+
32+
## Requirements
33+
- Docker & docker-compose
34+
- Switcher API & Switcher Management
35+
- Git Token (read/write access) for the repository
36+
37+
1. Configure Switcher API to allow Switcher GitOps to access the API<br>
38+
Set SWITCHER_GITOPS_JWT_SECRET for Switcher API and SWITCHER_API_JWT_SECRET for Switcher GitOps.
39+
40+
2. [Start](https://github.com/switcherapi/switcher-api?tab=readme-ov-file#running-switcher-api-from-docker-composer-manifest-file) Switcher API and Switcher Management
41+
3. Start Switcher GitOps `docker-compose -d up`<br>
42+
You might need to remove mongodb setting from docker-compose.yml if lauching the full Switcher API stack from the step 2.
43+
44+
3045
# Integrated tests
3146

3247
Set up PAT (Personal Access Token) for Switcher GitOps to access the repository. You can either create a fine-grained token with only the necessary permissions such as Content (Read and Write) and Metadata (Read) or use a personal token with full access.

docker-compose.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
version: '3.8'
2+
3+
volumes:
4+
mongodb_data:
5+
driver: local
6+
7+
networks:
8+
backend:
9+
driver: bridge
10+
11+
services:
12+
mongodb:
13+
image : mongo
14+
container_name: mongodb
15+
environment:
16+
MONGO_INITDB_DATABASE: switcher-gitops
17+
volumes:
18+
- mongodb_data:/data/db
19+
ports:
20+
- 27017:27017
21+
networks:
22+
- backend
23+
restart: unless-stopped
24+
25+
switchergitops:
26+
image: trackerforce/switcher-gitops
27+
container_name: switchergitops
28+
command: ["/app"]
29+
ports:
30+
- 8000:8000
31+
networks:
32+
- backend
33+
environment:
34+
- RELEASE_TIME=today
35+
- PORT=8000
36+
- LOG_LEVEL=DEBUG
37+
38+
- MONGO_URI=mongodb://mongodb:27017
39+
- MONGO_DB=switcher-gitops
40+
- GIT_TOKEN_PRIVATE_KEY=SecretSecretSecretSecretSecretSe
41+
- HANDLER_WAITING_TIME=1m
42+
43+
- SWITCHER_API_URL=https://switcherapi.com/api
44+
- SWITCHER_API_JWT_SECRET=SecretSecretSecretSecretSecretSe
45+
- SWITCHER_PATH_GRAPHQL=/gitops-graphql
46+
- SWITCHER_PATH_PUSH=/gitops/v1/push
47+
depends_on:
48+
- mongodb

0 commit comments

Comments
 (0)