Skip to content

Add run script and set execution environment variable in Dockerfile #4

Add run script and set execution environment variable in Dockerfile

Add run script and set execution environment variable in Dockerfile #4

name: Docker
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
push:
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]
env:
REGISTRY:
IMAGE_NAME: ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKERHUB_REPO }}
jobs:
build_latest:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@main
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image (without tag for pull request)
if: github.event_name == 'pull_request'
run: docker build -f Dockerfile .
- name: Build image
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: docker build -f Dockerfile --tag ${IMAGE_NAME}:latest .
- name: Login to Dockerhub container registry
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: docker login -u ${{ vars.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push image
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: docker push ${IMAGE_NAME}:latest
build_release:
# Build an extra image for tagged commits
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags')
steps:
- name: Checkout
uses: actions/checkout@main
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image
run: docker build -f Dockerfile --tag ${IMAGE_NAME}:${{ github.ref_name }} .
- name: Login to Dockerhub container registry
run: docker login -u ${{ vars.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push image
run: docker push ${IMAGE_NAME}:${{ github.ref_name }}