ci: add docker scripts
This commit is contained in:
parent
09acca956c
commit
4868e4d7cf
|
@ -1,17 +0,0 @@
|
||||||
run-name: ${{ gitea.actor }}, deploy log101.dev services
|
|
||||||
on: [push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: "1.21.x"
|
|
||||||
- name: Install dependencies
|
|
||||||
run: go get .
|
|
||||||
- name: Build
|
|
||||||
run: go build -v ./...
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -23,3 +23,4 @@ go.work
|
||||||
|
|
||||||
gin-bin
|
gin-bin
|
||||||
TODO
|
TODO
|
||||||
|
.env
|
||||||
|
|
32
docker-compose.yml
Normal file
32
docker-compose.yml
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
dockerfile: docker/go/Dockerfile
|
||||||
|
container_name: go_gin_app
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: mysql:8.0
|
||||||
|
container_name: mysql_db
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- db_data:/var/lib/mysql
|
||||||
|
- ./schema.sql:/docker-entrypoint-initdb.d/schema.sql
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
|
||||||
|
interval: 2s
|
||||||
|
timeout: 20s
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
12
docker/go/Dockerfile
Normal file
12
docker/go/Dockerfile
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
FROM golang:1.22.3
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download && go mod verify
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN go build -v -o /usr/local/bin/app ./...
|
||||||
|
|
||||||
|
CMD ["app"]
|
5
main.go
5
main.go
|
@ -66,11 +66,12 @@ func countEmojis(postId string) ([]EmojiCount, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
mysqlHost := os.Getenv("DBHOST")
|
||||||
cfg := mysql.Config{
|
cfg := mysql.Config{
|
||||||
User: os.Getenv("DBUSER"),
|
User: os.Getenv("DBUSER"),
|
||||||
Passwd: os.Getenv("DBPASS"),
|
Passwd: os.Getenv("DBPASS"),
|
||||||
Net: "tcp",
|
Net: "tcp",
|
||||||
Addr: "127.0.0.1:3306",
|
Addr: mysqlHost + ":3306",
|
||||||
DBName: "emojis",
|
DBName: "emojis",
|
||||||
}
|
}
|
||||||
// Get a database handle.
|
// Get a database handle.
|
||||||
|
@ -145,5 +146,5 @@ func main() {
|
||||||
c.HTML(http.StatusOK, "emoji_form.tmpl", gin.H{"postId": postId, "results": emojiCounter})
|
c.HTML(http.StatusOK, "emoji_form.tmpl", gin.H{"postId": postId, "results": emojiCounter})
|
||||||
})
|
})
|
||||||
|
|
||||||
r.Run(":3001")
|
r.Run(":8000")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
-- schema.sql
|
-- schema.sql
|
||||||
|
CREATE DATABASE IF NOT EXISTS emojis;
|
||||||
|
|
||||||
|
USE emojis;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS emoji_clicks (
|
CREATE TABLE IF NOT EXISTS emoji_clicks (
|
||||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
post_id TEXT NOT NULL,
|
post_id TEXT NOT NULL,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user