42 lines
1 KiB
YAML
42 lines
1 KiB
YAML
name: Docker Build and Push
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- dev
|
|
|
|
jobs:
|
|
|
|
login:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
-
|
|
name: Login to Docker Hub
|
|
uses: docker/login-action@v2
|
|
with:
|
|
username: ${{ secrets.DOCKER_USER }}
|
|
password: ${{ secrets.DOCKER_TOKEN }}
|
|
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Build and push Docker image
|
|
env:
|
|
DOCKER_IMAGE_NAME: tibber-influx
|
|
run: |
|
|
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
|
DOCKER_TAG="latest"
|
|
elif [ "${{ github.ref }}" == "refs/heads/dev" ]; then
|
|
DOCKER_TAG="dev"
|
|
else
|
|
DOCKER_TAG="other"
|
|
fi
|
|
|
|
docker build -t $DOCKER_IMAGE_NAME .
|
|
docker tag $DOCKER_IMAGE_NAME:latest ${{ secrets.DOCKER_USER }}/$DOCKER_IMAGE_NAME:$DOCKER_TAG
|
|
docker push ${{ secrets.DOCKER_USER }}/$DOCKER_IMAGE_NAME:$DOCKER_TAG
|