ci: add docker scripts

This commit is contained in:
log101 2024-05-30 12:52:18 +03:00
parent 09acca956c
commit 4868e4d7cf
6 changed files with 52 additions and 19 deletions

View File

@ -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
View File

@ -23,3 +23,4 @@ go.work
gin-bin
TODO
.env

32
docker-compose.yml Normal file
View 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
View 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"]

View File

@ -66,11 +66,12 @@ func countEmojis(postId string) ([]EmojiCount, error) {
}
func main() {
mysqlHost := os.Getenv("DBHOST")
cfg := mysql.Config{
User: os.Getenv("DBUSER"),
Passwd: os.Getenv("DBPASS"),
Net: "tcp",
Addr: "127.0.0.1:3306",
Addr: mysqlHost + ":3306",
DBName: "emojis",
}
// Get a database handle.
@ -145,5 +146,5 @@ func main() {
c.HTML(http.StatusOK, "emoji_form.tmpl", gin.H{"postId": postId, "results": emojiCounter})
})
r.Run(":3001")
r.Run(":8000")
}

View File

@ -1,4 +1,8 @@
-- schema.sql
CREATE DATABASE IF NOT EXISTS emojis;
USE emojis;
CREATE TABLE IF NOT EXISTS emoji_clicks (
id INT PRIMARY KEY AUTO_INCREMENT,
post_id TEXT NOT NULL,