Skip to content

Commit 38cdaaa

Browse files
authored
Merge pull request #46 from ravilock/fix/check-for-tsuru-yaml-before-image-command-fallback
fix: check if tsuru.yaml has process commands before fallbacking to i…
1 parent 37aebb2 commit 38cdaaa

File tree

18 files changed

+1328
-361
lines changed

18 files changed

+1328
-361
lines changed

.github/workflows/ci.yaml

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,94 +4,94 @@ jobs:
44
test:
55
runs-on: ubuntu-latest
66
steps:
7-
- uses: actions/setup-go@v3
8-
with:
9-
go-version: '1.24'
7+
- uses: actions/setup-go@v3
8+
with:
9+
go-version: "1.24"
1010

11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v2
1212

13-
# NOTE: using link-local reserved address block in order to avoid conflict.
14-
- name: Add fake IP (169.196.255.254) on loopback interface
15-
run: |-
16-
{ ip address | grep -q 169.196.255.254; } || sudo ip address add 169.196.255.254 dev lo
13+
# NOTE: using link-local reserved address block in order to avoid conflict.
14+
- name: Add fake IP (169.196.255.254) on loopback interface
15+
run: |-
16+
{ ip address | grep -q 169.196.255.254; } || sudo ip address add 169.196.255.254 dev lo
1717
18-
- name: Running required services (Builkit, Docker Registry, Docker)
19-
run: docker compose -f ./compose.yaml up -d
18+
- name: Running required services (Builkit, Docker Registry, Docker)
19+
run: docker compose -f ./docker-compose.yaml up -d
2020

21-
- name: Install protoc and Go compiler plugins
22-
run: |-
23-
sudo apt install -y protobuf-compiler
24-
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
25-
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
21+
- name: Install protoc and Go compiler plugins
22+
run: |-
23+
sudo apt install -y protobuf-compiler
24+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
25+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
2626
27-
- run: make test test/integration
27+
- run: make test test/integration
2828

2929
lint:
3030
runs-on: ubuntu-latest
3131
steps:
32-
- uses: actions/setup-go@v3
33-
with:
34-
go-version: '1.24'
35-
- uses: actions/checkout@v2
36-
- uses: golangci/golangci-lint-action@v3
32+
- uses: actions/setup-go@v3
33+
with:
34+
go-version: "1.24"
35+
- uses: actions/checkout@v2
36+
- uses: golangci/golangci-lint-action@v3
3737

3838
publish:
3939
if: github.repository == 'tsuru/deploy-agent' && github.event_name != 'pull_request'
4040
needs:
41-
- lint
42-
- test
41+
- lint
42+
- test
4343
runs-on: ubuntu-latest
4444
steps:
45-
- name: Checkout
46-
uses: actions/checkout@v4
47-
- name: Set up QEMU
48-
uses: docker/setup-qemu-action@v3
49-
- name: Set up Docker Buildx
50-
uses: docker/setup-buildx-action@v3
51-
- uses: Surgo/docker-smart-tag-action@v1
52-
id: smarttag
53-
with:
54-
docker_image: tsuru/deploy-agent
55-
default_branch: main
56-
tag_with_sha: 'true'
57-
- name: Handle smart-tag to proper tag var
58-
uses: actions/github-script@v6
59-
id: handle_tag
60-
with:
61-
script: |
62-
var tag_re = /deploy-agent:([0-9])/g
63-
var orig_tags = `${{steps.smarttag.outputs.tag}}`
64-
return orig_tags.replace(tag_re,"deploy-agent:v$1")
65-
- name: docker login
66-
uses: docker/login-action@v3
67-
with:
68-
username: ${{ secrets.REGISTRY_USERNAME }}
69-
password: ${{ secrets.REGISTRY_PASSWORD }}
70-
- name: push image tag to Docker Hub (tsuru/deploy-agent)
71-
uses: docker/build-push-action@v5
72-
with:
73-
context: .
74-
push: true
75-
tags: ${{ steps.handle_tag.outputs.result }}
76-
platforms: linux/amd64,linux/arm64
45+
- name: Checkout
46+
uses: actions/checkout@v4
47+
- name: Set up QEMU
48+
uses: docker/setup-qemu-action@v3
49+
- name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@v3
51+
- uses: Surgo/docker-smart-tag-action@v1
52+
id: smarttag
53+
with:
54+
docker_image: tsuru/deploy-agent
55+
default_branch: main
56+
tag_with_sha: "true"
57+
- name: Handle smart-tag to proper tag var
58+
uses: actions/github-script@v6
59+
id: handle_tag
60+
with:
61+
script: |
62+
var tag_re = /deploy-agent:([0-9])/g
63+
var orig_tags = `${{steps.smarttag.outputs.tag}}`
64+
return orig_tags.replace(tag_re,"deploy-agent:v$1")
65+
- name: docker login
66+
uses: docker/login-action@v3
67+
with:
68+
username: ${{ secrets.REGISTRY_USERNAME }}
69+
password: ${{ secrets.REGISTRY_PASSWORD }}
70+
- name: push image tag to Docker Hub (tsuru/deploy-agent)
71+
uses: docker/build-push-action@v5
72+
with:
73+
context: .
74+
push: true
75+
tags: ${{ steps.handle_tag.outputs.result }}
76+
platforms: linux/amd64,linux/arm64
7777

7878
release:
7979
if: github.event_name != 'pull_request' && github.repository == 'tsuru/deploy-agent' && startsWith(github.ref, 'refs/tags/')
8080
needs:
81-
- lint
82-
- test
81+
- lint
82+
- test
8383
runs-on: ubuntu-latest
8484
steps:
85-
- name: Set up QEMU
86-
uses: docker/setup-qemu-action@v2
87-
- uses: actions/setup-go@v3
88-
with:
89-
go-version: '1.24'
90-
- uses: actions/checkout@v3
91-
with:
92-
fetch-depth: 0
93-
- uses: goreleaser/goreleaser-action@v2
94-
with:
95-
args: release
96-
env:
97-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
- name: Set up QEMU
86+
uses: docker/setup-qemu-action@v2
87+
- uses: actions/setup-go@v3
88+
with:
89+
go-version: "1.24"
90+
- uses: actions/checkout@v3
91+
with:
92+
fetch-depth: 0
93+
- uses: goreleaser/goreleaser-action@v2
94+
with:
95+
args: release
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,23 @@ GOLANGCI_LINT ?= golangci-lint
33
PROTOC ?= protoc
44
DOCKER ?= docker
55

6+
# check if user uses docker-compose standalone or compose plugin
7+
DOCKER_COMPOSE := $(shell if $(DOCKER) compose version > /dev/null 2>&1; then echo "$(DOCKER) compose"; else echo "docker-compose"; fi)
8+
69
INTERNAL_IP ?= 169.196.255.254
710

11+
LOCAL_DEV ?= ./misc/local-dev.sh
12+
13+
.PHONY: setup
14+
setup:
15+
@$(LOCAL_DEV) setup-loopback $(TSURU_HOST_IP)
16+
@$(DOCKER_COMPOSE) up -d
17+
18+
.PHONY: cleanup
19+
cleanup:
20+
@$(DOCKER_COMPOSE) down
21+
@$(LOCAL_DEV) cleanup-loopback $(TSURU_HOST_IP)
22+
823
.PHONY: all
924
all: lint test
1025

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,53 @@ It exposes a well-defined API over a gRPC service that translates all Tsuru oper
77

88
[Cloud Build]: https://cloud.google.com/build
99
[kaniko]: https://github.com/GoogleContainerTools/kaniko
10+
11+
## Local Development Setup
12+
13+
To set up your local development environment for deploy-agent, follow these steps:
14+
15+
1. **Install Dependencies**
16+
- Ensure you have Docker and Docker Compose (or the Docker Compose plugin) installed.
17+
- Install Go (version 1.24 or higher).
18+
- Install `protoc` (Protocol Buffers compiler).
19+
20+
2. **Prepare Loopback IP**
21+
- The project uses a reserved IP (`169.196.255.254`) on the loopback interface for local registry and Docker communication.
22+
- Use the provided script to set up the loopback IP:
23+
24+
```sh
25+
make setup
26+
```
27+
28+
- This will:
29+
- Assign the fake IP to your loopback interface.
30+
- Start Buildkit, Docker Registry, and Docker-in-Docker services using Docker Compose.
31+
32+
3. **Run Tests**
33+
- To run all tests (including integration tests):
34+
35+
```sh
36+
make test test/integration
37+
```
38+
39+
4. **Cleanup**
40+
- To stop services and remove the fake IP from your loopback interface:
41+
42+
```sh
43+
make cleanup
44+
```
45+
46+
5. **Other Useful Commands**
47+
- Lint the code:
48+
49+
```sh
50+
make lint
51+
```
52+
53+
- Build the container image:
54+
55+
```sh
56+
make build/container-image
57+
```
58+
59+
> The `misc/local-dev.sh` script handles loopback IP setup/cleanup and works on both Linux and macOS.

compose.yaml renamed to docker-compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ services:
77
command: --addr tcp://0.0.0.0:7777 --config /etc/buildkit/buildkitd.toml
88
privileged: true
99
ports:
10-
- 7777:7777
10+
- 7777:7777
1111
volumes:
12-
- ./pkg/build/buildkit/testdata/buildkitd.toml:/etc/buildkit/buildkitd.toml:ro
12+
- ./pkg/build/buildkit/testdata/buildkitd.toml:/etc/buildkit/buildkitd.toml:ro
1313

1414
registry:
1515
container_name: registry
1616
image: registry:2
1717
ports:
18-
- 5000:5000
18+
- 5000:5000
1919

2020
docker:
2121
container_name: docker
2222
image: docker:20.10.3-dind
2323
command: dockerd -H tcp://0.0.0.0:2375 --insecure-registry 169.196.255.254:5000 --storage-driver overlay2
2424
privileged: true
2525
ports:
26-
- 2375:2375
26+
- 2375:2375

0 commit comments

Comments
 (0)