Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to github actions #139

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Go Build & Test
on:
push:
branches:
- master
tags:
- '**'
pull_request:
workflow_dispatch:

jobs:
build-and-test:
runs-on: ubuntu-latest

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Build and run tests
run: |
go install ./...
go test -short -v ./...
_script/run-e2e.sh read

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
docker.io/${{ github.repository }}
tags: |
type=edge
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha

- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

14 changes: 5 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
# Copyright 2020 Adevinta

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

WORKDIR /app

ARG TARGETOS TARGETARCH

COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .

RUN cd cmd/vulnerability-db-api/ && GOOS=linux GOARCH=amd64 go build . && cd -
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build ./cmd/vulnerability-db-api

FROM alpine:3.21

RUN apk add --no-cache --update bash gettext

WORKDIR /app

ARG BUILD_RFC3339="1970-01-01T00:00:00Z"
ARG COMMIT="local"

ENV BUILD_RFC3339 "$BUILD_RFC3339"
ENV COMMIT "$COMMIT"

COPY --from=builder /app/cmd/vulnerability-db-api/vulnerability-db-api .
COPY --from=builder /app/vulnerability-db-api .

COPY config.toml .
COPY run.sh .
Expand Down
2 changes: 1 addition & 1 deletion _resources/postgres-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# Copyright 2020 Adevinta

docker-compose up -d
docker compose up -d
4 changes: 2 additions & 2 deletions _resources/postgres-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# Copyright 2020 Adevinta

docker-compose kill
docker-compose rm -f
docker compose kill
docker compose rm -f
6 changes: 3 additions & 3 deletions _script/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ case $ARG in
esac

# Start postgress databases.
docker-compose -f _resources/docker-compose-e2e.yml -p e2e up --quiet-pull -d $SERVICE
docker compose -f _resources/docker-compose-e2e.yml -p e2e up --quiet-pull -d $SERVICE

# Set up schema for the test db.
VDB=$(mktemp -d)
Expand All @@ -60,10 +60,10 @@ vulnerability-db-api -c $CONFIG_FILE &

# Run e2e tests.
echo "RUNNING e2e tests"
docker-compose -f _resources/docker-compose-e2e.yml -p "e2e" run e2e
docker compose -f _resources/docker-compose-e2e.yml -p "e2e" run --quiet-pull e2e

# Clean up resurces.
set +e
pkill vulnerability-db-api
set -e
docker-compose -f _resources/docker-compose-e2e.yml -p "e2e" rm -s -f -v
docker compose -f _resources/docker-compose-e2e.yml -p "e2e" rm -s -f -v
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/adevinta/vulnerability-db-api

go 1.21.2
go 1.23.0

toolchain go1.24.1

require (
Expand Down