-
Notifications
You must be signed in to change notification settings - Fork 0
49 lines (40 loc) · 2.3 KB
/
docker-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: Docker # Name of the workflow
on:
push:
branches: [ main ] # Workflow to run only when changes are made to `main` branch
env:
REGISTRY: ghcr.io # Image registry, ghcr.io incase of GitHub Container Registry
IMAGE_NAME: ${{ github.repository }} # Name of the image comes from the repository name
jobs:
release:
runs-on: ubuntu-latest # GitHub Runner OS
steps:
- name: Checkout source code # Checksout the repository in the GitHub runner
uses: 'actions/checkout@v3'
with:
ref: ${{ github.ref }}
- name: Run read-yaml action
id: yaml-data
uses: KJ002/read-yaml@main # You may wish to replace main with a version tag such as '1.6' etc.
with:
file: './src/bashly.yml' # File to read from
key-path: '["version"]' # Access the runs key then the using key and retuns the value.
- name: Output Step # Optional: Prints the new version
env:
NEW_TAG: ${{ steps.yaml-data.outputs.data }}
run: echo "new tag $NEW_TAG"
- name: Log into registry ${{ env.REGISTRY }} # Log into the container registry from GitHub runner
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }} # Uses the env defined above
username: ${{ github.actor }} # GitHub Secret added to the repository
password: ${{ secrets.GITHUB_TOKEN }} # GitHub Secret added to the repository
- name: Build and push Docker image # Builds and pushes the image to the conatiner registry
uses: docker/build-push-action@v4
with:
context: . # Folder where the Dockerfile resides, use `/` if in root path
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.yaml-data.outputs.data }}
secrets: |
GIT_AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }}
# Pushed the image with `latest` tag and the new semantic version obtained from the version-bump step