Skip to content

Commit

Permalink
chore: add CI/CD workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
slowhigh committed May 24, 2024
1 parent 6683982 commit c22b18f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: cd

on:
push:
branches:
- main

concurrency:
group: cd
cancel-in-progress: true

jobs:
deploy_api_server:
name: Push Docker image to Docker Hub, Deploy API Server.
runs-on: ubuntu-latest

steps:
- name: Check out the repo
uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}

- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "::set-output name=short_sha::$calculatedSha"
- name: Confirm git commit SHA output
run: echo ${{ steps.vars.outputs.short_sha }}

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

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/api-server:${{ steps.vars.outputs.short_sha }}

- name: Deploy to K8S
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script: kubectl set image deploy/api-server api-server=${{ secrets.DOCKERHUB_USERNAME }}/api-server:${{ steps.vars.outputs.short_sha }}
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: ci

on:
push:
branches:
- main

concurrency:
group: ci
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: './consumer/go.mod'

- name: Build
working-directory: ./consumer
run: go build -v -o ./server ./cmd/server

- name: Test
working-directory: ./consumer
run: go test -v ./cmd/server
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:alpine

WORKDIR /app

COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .

RUN go build -o ./server ./cmd/server

CMD [ "./server" ]

0 comments on commit c22b18f

Please sign in to comment.