chore: Improve Github workflows #202
This file contains hidden or 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: Push docker image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| test: | |
| name: Testing | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres | |
| ports: | |
| - "5433:5432" | |
| env: | |
| POSTGRES_PASSWORD: password_test | |
| POSTGRES_USER: nebula_test | |
| POSTGRES_DB: nebula_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| clickhouse: | |
| image: clickhouse/clickhouse-server:24.12 | |
| ports: | |
| - "8124:8123" | |
| - "9001:9000" | |
| env: | |
| CLICKHOUSE_PASSWORD: password_test | |
| CLICKHOUSE_USER: nebula_test | |
| CLICKHOUSE_DB: nebula_test | |
| options: >- | |
| --health-cmd "clickhouse-client --query=\"SELECT 1\"" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - name: Checking out repository code | |
| uses: actions/checkout@v4 | |
| - name: Setting up Golang | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: 'go.mod' | |
| - name: Setting up just | |
| uses: extractions/setup-just@v3 | |
| - name: Running tests | |
| run: just test-plain | |
| push_to_dockerhub: | |
| name: Push Docker image to Docker Hub | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@v4 | |
| - name: Setting up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Setting up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: dennistra/nebula-crawler | |
| tags: | | |
| type=sha | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| push_to_ecr: | |
| name: Push Docker image to ProbeLab's ECR | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| - name: Checking out the repo | |
| uses: actions/checkout@v4 | |
| - name: Configuring AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-region: us-east-1 | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
| aws-secret-access-key: ${{ secrets.AWS_ACCESS_SECRET }} | |
| - name: Log in to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Setting up just | |
| uses: extractions/setup-just@v3 | |
| - name: Build, tag, and push docker image to Amazon ECR | |
| env: | |
| REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| REPOSITORY: probelab | |
| run: | | |
| SHA_SHORT=${{ github.sha }} | |
| SHA_SHORT=${SHA_SHORT::7} | |
| IMAGE_TAG="nebula-sha${SHA_SHORT}" | |
| docker build \ | |
| --build-arg VERSION=$(cat version) \ | |
| --build-arg COMMIT=$SHA_SHORT \ | |
| --build-arg BUILT_BY=ghaction \ | |
| --build-arg DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ | |
| -t $REGISTRY/$REPOSITORY:$IMAGE_TAG \ | |
| . | |
| docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG |