ci #3208
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ci | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
schedule: | |
- cron: '0 0 * * *' # Runs every day at 00:00 UTC | |
jobs: | |
gotest: | |
name: Test Backend | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Go 1.x | |
uses: actions/setup-go@v5 | |
with: | |
go-version: "1.23" | |
id: go | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
- name: Build | |
run: go build -v ./... | |
- name: gofmt | |
run: | | |
GOFMTOUT=$(gofmt -l .) | |
if [[ ! -z "${GOFMTOUT}" ]]; then | |
echo "FATAL: gofmt violation(s), please fix" | |
echo $GOFMTOUT | |
exit -1 | |
fi | |
- name: go vet | |
run: go vet ./... | |
- name: Test | |
run: | | |
docker run --rm -d -v $(pwd)/backend/schema.sql:/docker-entrypoint-initdb.d/schema.sql -e MYSQL_DATABASE=dev-db -e MYSQL_ROOT_PASSWORD=dev-root-password -e MYSQL_USER=dev-user -e MYSQL_PASSWORD=dev-user-password -p3306:3306 mysql | |
while ! mysqladmin ping -h"127.0.0.1" --silent; do | |
sleep 1 | |
done | |
go test -v ./... | |
build_push: | |
name: Build and Push | |
needs: [gotest] | |
strategy: | |
matrix: | |
service: [frontend,web,api,init] | |
fail-fast: false | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Docker meta | |
id: docker_meta | |
uses: docker/metadata-action@v5.5.1 | |
with: | |
images: ashirt/${{ matrix.service }} # list of Docker images to use as base name for tags | |
tags: | | |
type=sha | |
type=ref,event=branch | |
type=ref,event=pr | |
flavor: | | |
latest=false | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3.3.0 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3.6.1 | |
- name: Build and Push PR | |
if: github.ref != 'refs/heads/main' | |
uses: docker/build-push-action@v6.7.0 | |
with: | |
context: . | |
file: Dockerfile.prod.${{ matrix.service }} | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
labels: ${{ steps.docker_meta.outputs.labels }} | |
platforms: linux/amd64,linux/arm64 | |
push: true # Push with pr-### and sha-xxxxxxx tags | |
- name: Build and Push Latest | |
if: github.ref == 'refs/heads/main' | |
uses: docker/build-push-action@v6.7.0 | |
with: | |
context: . | |
file: Dockerfile.prod.${{ matrix.service }} | |
tags: ${{ steps.docker_meta.outputs.tags }}, ashirt/${{ matrix.service }}:latest #Add latest tag for main | |
labels: ${{ steps.docker_meta.outputs.labels }} | |
platforms: linux/amd64,linux/arm64 | |
push: true |