Skip to content

Commit 96aada3

Browse files
committed
upgrade go & mysql versions
1 parent e6c2835 commit 96aada3

File tree

15 files changed

+148
-109
lines changed

15 files changed

+148
-109
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,19 @@ on:
99

1010
jobs:
1111
test:
12-
name: Test
1312
runs-on: ubuntu-latest
14-
services:
15-
mysql:
16-
image: mysql:5.7
17-
env:
18-
MYSQL_ROOT_PASSWORD: 123
19-
MYSQL_DATABASE: test
20-
options: >-
21-
--health-cmd="mysqladmin ping"
22-
--health-interval=10s
23-
--health-timeout=5s
24-
--health-retries=3
25-
ports:
26-
# Maps tcp port 3306 on service container to the host
27-
- 3306:3306
2813
steps:
29-
- uses: actions/setup-go@v2
30-
with:
31-
go-version: 1.15
32-
33-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
3415

35-
- name: Lint
36-
uses: golangci/golangci-lint-action@v2
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
3718
with:
38-
version: v1.31
19+
go-version: '1.23'
3920

40-
- name: Get dependencies
41-
run: go mod download
42-
43-
- name: Test
44-
run: go test -race -v -covermode atomic -coverprofile=covprofile ./...
21+
- name: Run tests
22+
run: make test
4523

4624
- name: Send coverage
4725
uses: shogo82148/actions-goveralls@v1
4826
with:
49-
path-to-profile: covprofile
50-
51-
goreleaser:
52-
name: Build and release binary
53-
needs: test
54-
runs-on: ubuntu-latest
55-
if: startsWith(github.ref, 'refs/tags/v')
56-
steps:
57-
- uses: actions/checkout@v2
58-
- uses: actions/setup-go@v2
59-
with:
60-
go-version: 1.15
61-
- uses: goreleaser/goreleaser-action@v2.2.1
62-
with:
63-
args: release --rm-dist
64-
env:
65-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
path-to-profile: ./coverage/covprofile

.github/workflows/release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: release
2+
on:
3+
release:
4+
types:
5+
- created
6+
jobs:
7+
goreleaser:
8+
runs-on: ubuntu-latest
9+
steps:
10+
-
11+
name: Checkout
12+
uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
-
16+
name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: 1.23.1
20+
-
21+
name: Run GoReleaser
22+
uses: goreleaser/goreleaser-action@v6
23+
with:
24+
version: '~> v2'
25+
args: release --clean
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile-mysql

Lines changed: 0 additions & 16 deletions
This file was deleted.

Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.PHONY: build up test lint
2+
3+
NAME := pas
4+
5+
build:
6+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o $(NAME)
7+
8+
MAIN_COMPOSE := docker compose -f ./build/docker-compose.yml
9+
build-docker:
10+
$(MAIN_COMPOSE) build pas
11+
mkdir -p ./bin
12+
docker create --name pas-builder pas
13+
docker cp pas-builder:/usr/local/bin/pas - > ./bin/pas
14+
docker rm -v pas-builder
15+
16+
MAIN_COMPOSE := docker compose -f ./build/docker-compose.yml
17+
up:
18+
$(MAIN_COMPOSE) build pas
19+
$(MAIN_COMPOSE) rm -fsv
20+
$(MAIN_COMPOSE) up pas --build --abort-on-container-exit
21+
22+
TEST_COMPOSE := docker compose -f ./build/docker-compose-test.yml
23+
test:
24+
$(TEST_COMPOSE) rm -fsv
25+
mkdir -p ./coverage
26+
$(TEST_COMPOSE) up pas-test --build --exit-code-from pas-test --abort-on-container-exit
27+
28+
lint:
29+
golangci-lint run

build/docker-compose-test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
services:
2+
mysql:
3+
image: pas/mysql
4+
container_name: pas-mysql
5+
build:
6+
dockerfile: ./build/mysql/Dockerfile
7+
context: ..
8+
environment:
9+
MYSQL_DATABASE: pas
10+
MYSQL_USER: pas
11+
MYSQL_PASSWORD: 123
12+
pas-test:
13+
image: pas/test
14+
container_name: pas-test
15+
build:
16+
dockerfile: ./build/test/Dockerfile
17+
context: ..
18+
depends_on:
19+
- mysql
20+
tty: true
21+
volumes:
22+
- ../coverage:/coverage
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
version: '3.2'
21
services:
32
mysql:
4-
image: pas-mysql
3+
image: pas/mysql
54
container_name: pas-mysql
65
build:
7-
dockerfile: Dockerfile-mysql
8-
context: .
6+
dockerfile: ./build/mysql/Dockerfile
7+
context: ..
98
ports:
109
- "3306:3306"
1110
pas:
1211
image: pas
1312
container_name: pas
1413
build:
15-
dockerfile: Dockerfile-pas
16-
context: .
14+
dockerfile: ./build/pas/Dockerfile
15+
context: ..
1716
depends_on:
1817
- mysql
1918
ports:

build/mysql/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM mysql:8
2+
3+
ENV MYSQL_USER=pas \
4+
MYSQL_PASSWORD=123 \
5+
MYSQL_DATABASE=pas \
6+
MYSQL_RANDOM_ROOT_PASSWORD=1

Dockerfile-pas renamed to build/pas/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM golang:1.15
1+
FROM golang:1.23.1
22

3-
WORKDIR /src
3+
WORKDIR /pas
44
COPY go.* ./
55
RUN go mod download
66

build/test/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM golang:1.23.1 AS builder
2+
3+
# Install mysql
4+
RUN apt-get update && \
5+
apt-get -y install --no-install-recommends default-mysql-client && \
6+
rm -rf /var/lib/apt/lists/*
7+
8+
WORKDIR /pas
9+
10+
COPY go.mod .
11+
COPY go.sum .
12+
RUN go mod download
13+
14+
COPY ./build/test/entrypoint.sh /root/entrypoint.sh
15+
COPY . .
16+
17+
ENTRYPOINT ["/bin/bash", "/root/entrypoint.sh"]

build/test/entrypoint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash -ex
2+
3+
mysql=(mysql -hmysql -upas -p123)
4+
max_attempts=30
5+
attempt=0
6+
7+
until "${mysql[@]}" -e "select 1" &>/dev/null ; do
8+
attempt=$(( attempt + 1 ))
9+
if [ $attempt -ge $max_attempts ]; then
10+
echo "Error: MySQL did not become ready within $max_attempts attempts"
11+
exit 1
12+
fi
13+
echo "MySQL is not ready yet... (attempt $attempt/$max_attempts)"
14+
sleep 1
15+
done
16+
echo "MySQL is ready."
17+
18+
exec go test -v -race -covermode atomic -coverprofile=/coverage/covprofile ./...

0 commit comments

Comments
 (0)