-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docker/docker-compose support and move GH actions to use docker-c…
…ompose by default
- Loading branch information
Showing
5 changed files
with
122 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
name: Backend Go CI | ||
|
||
# Events that trigger this workflow | ||
on: [push, pull_request] | ||
|
||
# Defines which tool versions should be used in all workflow jobs | ||
env: | ||
go: "1.21" | ||
on: [ push, pull_request ] | ||
|
||
defaults: | ||
run: | ||
|
@@ -18,44 +14,20 @@ jobs: | |
steps: | ||
- name: Checkout 📥 | ||
uses: actions/[email protected] | ||
- name: Setup Go 💿 | ||
uses: actions/[email protected] | ||
with: | ||
go-version: ${{ env.go }} | ||
cache-dependency-path: backend-go/go.sum | ||
- name: Install dependencies 📚 | ||
run: go get . | ||
- name: Check code style 🧽 | ||
shell: bash | ||
run: | | ||
test "$(gofmt -e -l . | wc -l)" -eq 0 | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout 📥 | ||
uses: actions/[email protected] | ||
- name: Setup Go 💿 | ||
uses: actions/[email protected] | ||
with: | ||
go-version: ${{ env.go }} | ||
cache-dependency-path: backend-go/go.sum | ||
- name: Install dependencies 📚 | ||
run: go get . | ||
- name: Build library 📦 | ||
run: go build -v ./... | ||
unit-test: | ||
name: Unit Test | ||
- name: Check style 🧽 | ||
run: docker compose --file docker-compose.ci.yml --profile style up --abort-on-container-exit | ||
- name: Stop containers 🛑 | ||
if: always() | ||
run: docker compose --file docker-compose.ci.yml --profile style down | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout 📥 | ||
uses: actions/[email protected] | ||
- name: Setup Go 💿 | ||
uses: actions/[email protected] | ||
with: | ||
go-version: ${{ env.go }} | ||
cache-dependency-path: backend-go/go.sum | ||
- name: Install dependencies 📚 | ||
run: go get . | ||
- name: Run unit tests 🛃 | ||
run: go test | ||
- name: Run tests 🛃 | ||
run: docker compose --file docker-compose.ci.yml --profile test up --abort-on-container-exit | ||
- name: Stop containers 🛑 | ||
if: always() | ||
run: docker compose --file docker-compose.ci.yml --profile test down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
http_port: 8222 | ||
|
||
websocket: { | ||
port: 9222 | ||
no_tls: true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM golang:1.21-alpine | ||
|
||
# creates an "invisible" docker volume during container startup | ||
# by retaining the go builc cache from the image build | ||
# to support different cpu architectures | ||
VOLUME /go | ||
|
||
# switch to app | ||
WORKDIR /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## | ||
## docker-compose configuration for GitHub Actions | ||
## | ||
|
||
services: | ||
style: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
command: > | ||
sh -c 'gofmt -e -l . && test "$(gofmt -e -l . | wc -l)" -eq 0' | ||
volumes: | ||
- .:/app | ||
profiles: [ 'style' ] | ||
|
||
test: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
command: [ 'go', 'test' ] | ||
volumes: | ||
- .:/app | ||
- ../backend-features:/backend-features | ||
profiles: [ 'test' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
services: | ||
|
||
## | ||
## go commands | ||
## | ||
|
||
style: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
command: [ "gofmt", "-w", "." ] | ||
volumes: | ||
- .:/app | ||
profiles: [ 'style' ] | ||
|
||
test: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
command: [ 'go', 'test' ] | ||
volumes: | ||
- .:/app | ||
- ../backend-features:/backend-features | ||
profiles: [ 'test' ] | ||
|
||
## | ||
## end-to-end example | ||
## | ||
|
||
sub: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
command: [ 'go', 'run', 'samples/sub/main.go', '--dev', '--NATS_URL=nats://nats:4222' ] | ||
volumes: | ||
- .:/app | ||
networks: [ 'nats-network' ] | ||
profiles: [ 'dev' ] | ||
depends_on: [ 'nats' ] | ||
restart: unless-stopped | ||
|
||
pub: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
command: [ 'go', 'run', 'samples/pub/main.go', '--dev', '--NATS_URL=nats://nats:4222' ] | ||
volumes: | ||
- .:/app | ||
networks: [ 'nats-network' ] | ||
profiles: [ 'dev' ] | ||
depends_on: [ 'nats' ] | ||
|
||
nats: | ||
image: nats:latest | ||
command: [ '-c', '/etc/nats/nats.conf' ] | ||
volumes: | ||
- ./.nats.conf:/etc/nats/nats.conf | ||
ports: | ||
- '0.0.0.0:4222:4222' | ||
- '127.0.0.1:8222:8222' | ||
- '127.0.0.1:6222:6222' | ||
- '0.0.0.0:9222:9222' | ||
networks: [ 'nats-network' ] | ||
profiles: [ 'dev' ] | ||
restart: unless-stopped | ||
|
||
networks: | ||
nats-network: | ||
name: nats-network |