Skip to content

Create build and publish to Harbor job #4

Create build and publish to Harbor job

Create build and publish to Harbor job #4

Workflow file for this run

name: CI/CD Pipeline
on: [push]
# push:
# branches:
# - "**"
# tags:
# - "v*.*.*"
# pull_request:
# branches:
# - "main"
jobs:
lint-and-test:
name: Run linter and tests
runs-on: [self-hosted, Linux]
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm install
- name: Linting
run: npm run lint
build-and-publish:
name: Create and push Docker image
needs: lint-and-test
# if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
runs-on: [self-hosted, Linux]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker
- name: Import secrets
id: import-secrets
uses: hashicorp/vault-action@v3
with:
url: ${{ secrets.VAULT_URL }}
method: approle
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}
secrets: |
kv/team/text/data/harbor *
- name: Log in to Harbor
uses: docker/login-action@v3
with:
registry: ${{ steps.import-secrets.outputs.HARBOR_URL }}
username: ${{ steps.import-secrets.outputs.HARBOR_USERNAME }}
password: ${{ steps.import-secrets.outputs.HARBOR_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: harbor.nb.no/tekst/hugin
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=ref,event=pr
- name: Build and push image
uses: docker/build-push-action@v5
with:
push: true
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: Dockerfile