Skip to content

Commit 186d1d8

Browse files
authored
Migrate to github actions (#163)
1 parent 9654b26 commit 186d1d8

File tree

11 files changed

+88
-50
lines changed

11 files changed

+88
-50
lines changed

.github/workflows/build.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Go Build & Test
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags:
7+
- '**'
8+
pull_request:
9+
workflow_dispatch:
10+
11+
jobs:
12+
build-and-test:
13+
runs-on: ubuntu-latest
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
env:
20+
FLYWAY_VERSION: "10.10.0"
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Login to Docker Hub
27+
uses: docker/login-action@v3
28+
if: github.event_name != 'pull_request'
29+
with:
30+
username: ${{ vars.DOCKERHUB_USERNAME }}
31+
password: ${{ secrets.DOCKERHUB_TOKEN }}
32+
33+
- name: Set up Go
34+
uses: actions/setup-go@v5
35+
with:
36+
go-version: stable
37+
38+
- name: Build and run tests
39+
run: |
40+
_script/start-pg
41+
go test -tags integration $(go list ./... | grep -v /vendor/) ./test
42+
cd local_deployment
43+
./test-local-deployment.sh
44+
45+
- name: Set up QEMU
46+
uses: docker/setup-qemu-action@v3
47+
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v3
50+
51+
- name: Docker meta
52+
id: meta
53+
uses: docker/metadata-action@v5
54+
with:
55+
images: |
56+
docker.io/${{ github.repository }}
57+
tags: |
58+
type=edge
59+
type=ref,event=branch
60+
type=semver,pattern={{version}}
61+
type=semver,pattern={{major}}.{{minor}}
62+
type=semver,pattern={{major}}
63+
type=sha
64+
65+
- name: Build and push
66+
uses: docker/build-push-action@v6
67+
with:
68+
build-args: FLYWAY_VERSION=${{ env.FLYWAY_VERSION }}
69+
platforms: linux/amd64,linux/arm64
70+
push: ${{ github.event_name != 'pull_request' }}
71+
tags: ${{ steps.meta.outputs.tags }}
72+
labels: ${{ steps.meta.outputs.labels }}

.travis.yml

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

Dockerfile

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright 2020 Adevinta
22

3-
FROM --platform=$BUILDPLATFORM golang:1.22-alpine3.18 as builder
3+
FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS builder
44

55
WORKDIR /app
66

@@ -13,7 +13,7 @@ COPY . .
1313

1414
ARG TARGETOS TARGETARCH
1515

16-
RUN cd cmd/vulnerability-db-consumer/ && GOOS=$TARGETOS GOARCH=$TARGETARCH go build . && cd -
16+
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build ./cmd/vulnerability-db-consumer
1717

1818
FROM alpine:3.21
1919

@@ -26,21 +26,15 @@ ARG FLYWAY_VERSION=10.10.0
2626
RUN wget -q https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/${FLYWAY_VERSION}/flyway-commandline-${FLYWAY_VERSION}.tar.gz \
2727
&& tar -xzf flyway-commandline-${FLYWAY_VERSION}.tar.gz --strip 1 \
2828
&& rm flyway-commandline-${FLYWAY_VERSION}.tar.gz \
29-
&& find ./drivers/ -type f | grep -Ev '(postgres|jackson)' | xargs rm \
29+
&& find ./drivers/ -type f -not -name '*postgres*' -not -name '*jackson*' -delete \
3030
&& chown -R root:root . \
3131
&& ln -s /flyway/flyway /bin/flyway
3232

3333
WORKDIR /app
3434

35-
ARG BUILD_RFC3339="1970-01-01T00:00:00Z"
36-
ARG COMMIT="local"
37-
38-
ENV BUILD_RFC3339 "$BUILD_RFC3339"
39-
ENV COMMIT "$COMMIT"
40-
4135
COPY db/sql/*.sql /app/sql/
4236

43-
COPY --from=builder /app/cmd/vulnerability-db-consumer/vulnerability-db-consumer .
37+
COPY --from=builder /app/vulnerability-db-consumer .
4438

4539
COPY config.toml .
4640
COPY run.sh .

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ application.
2424
cd local_deployment
2525

2626
# Start the dependencies
27-
docker-compose up -d
27+
docker compose up -d
2828

2929
# Build and run the vulnerability-db-consumer
3030
./start.sh
@@ -51,7 +51,7 @@ AWS_ACCESS_KEY_ID=fake AWS_SECRET_ACCESS_KEY=fake aws sns publish \
5151

5252
To stop the dependencies, run:
5353
```bash
54-
docker-compose down --remove-orphans
54+
docker compose down --remove-orphans
5555
```
5656

5757
To purge local mocked SQS queue:

_script/start-pg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
set -e
66

7-
docker run --name postgres -p 5432:5432 -e POSTGRES_USER=vulndb_test -e POSTGRES_PASSWORD=vulndb_test --rm -d postgres:13.3-alpine
7+
docker run -q --name postgres -p 5432:5432 -e POSTGRES_USER=vulndb_test -e POSTGRES_PASSWORD=vulndb_test --rm -d postgres:13.3-alpine
88

99
sleep 2
1010

11-
while ! docker exec -it postgres pg_isready; do echo "Waiting for postgres" && sleep 2; done;
11+
while ! docker exec postgres pg_isready; do echo "Waiting for postgres" && sleep 2; done;

_script/test_local

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ host=localhost
88
port=5432
99

1010
# setup test db
11-
docker-compose -f $(pwd)/test/docker-compose.yml up -d
11+
docker compose -f $(pwd)/test/docker-compose.yml up --quiet-pull -d
1212

1313
echo Waiting for postgres to become available...
1414
while ! nc -z $host $port 2>/dev/null

db/flyway-migrate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
# Copyright 2020 Adevinta
44

5-
docker run --net=host -v "$PWD"/sql:/flyway/sql flyway/flyway:"${FLYWAY_VERSION:-10}-alpine" \
5+
docker run -q --net=host -v "$PWD"/sql:/flyway/sql flyway/flyway:"${FLYWAY_VERSION:-10}-alpine" \
66
-user=vulndb -password=vulndb -url=jdbc:postgresql://localhost:5438/vulndb -baselineOnMigrate=true migrate

db/postgres-start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
# Copyright 2020 Adevinta
44

5-
docker-compose up -d
5+
docker compose up -d --quiet-pull

db/postgres-stop.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
# Copyright 2020 Adevinta
44

5-
docker-compose kill
6-
docker-compose rm -f
5+
docker compose kill
6+
docker compose rm -f

local_deployment/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
- ./mocked_database/config.env
1515

1616
mocked_sns_sqs:
17-
image: pafortin/goaws:v0.3.1
17+
image: admiralpiett/goaws:v0.5.3
1818
ports:
1919
- 4100:4100
2020
volumes:

local_deployment/test-local-deployment.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash
22

3-
docker-compose up -d
3+
docker compose up -d --quiet-pull
44

55
sleep 5
66

77
./start.sh &
88

9-
AWS_ACCESS_KEY_ID=fake AWS_SECRET_ACCESS_KEY=fake aws sns publish --region local --endpoint-url http://localhost:4100 --topic-arn arn:aws:sns:local:012345678900:VulcanLocalhostChecks --message \
9+
docker run -q --rm -e AWS_ACCESS_KEY_ID=fake -e AWS_SECRET_ACCESS_KEY=fake --network=host amazon/aws-cli:2.25.2 sns publish --region local --endpoint-url http://localhost:4100 --topic-arn arn:aws:sns:local:012345678900:VulcanLocalhostChecks --message \
1010
'{
1111
"status":"FINISHED",
1212
"id":"old-model-happy-path-01",

0 commit comments

Comments
 (0)