-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
name: Docker Image Push | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
merge_group: | ||
pull_request: | ||
branches: [main] | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
required: true | ||
type: choice | ||
description: version | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
REGISTRY: docker.io | ||
IMAGE_NAME: trueberryless/true-tracker | ||
NODE_VERSION: 18 | ||
|
||
jobs: | ||
docker-push-image: | ||
if: contains(github.event.head_commit.message, 'version') || github.event_name == 'workflow_dispatch' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Check if file exists | ||
run: | | ||
if [ -f .github/artifacts/version.json ]; then | ||
echo "File exists" | ||
echo "FILE_EXISTS=true" >> $GITHUB_ENV | ||
else | ||
echo "File does not exist" | ||
echo "FILE_EXISTS=false" >> $GITHUB_ENV | ||
fi | ||
- name: read_json | ||
if: ${{ env.FILE_EXISTS == 'true' }} | ||
id: version | ||
uses: zoexx/github-action-json-file-properties@release | ||
with: | ||
file_path: ".github/artifacts/version.json" | ||
|
||
- name: save environment variables | ||
if: ${{ env.FILE_EXISTS == 'true' }} | ||
run: | | ||
echo "MAJOR=${{steps.version.outputs.major}}" >> $GITHUB_ENV | ||
echo "MINOR=${{steps.version.outputs.minor}}" >> $GITHUB_ENV | ||
echo "PATCH=${{steps.version.outputs.patch}}" >> $GITHUB_ENV | ||
- name: create environment variables | ||
if: ${{ env.FILE_EXISTS == 'false' }} | ||
run: | | ||
echo "MAJOR=0" >> $GITHUB_ENV | ||
echo "MINOR=0" >> $GITHUB_ENV | ||
echo "PATCH=0" >> $GITHUB_ENV | ||
- name: echo environment variables | ||
run: | | ||
echo ${{ env.MINOR }} | ||
echo ${{ env.MINOR }} | ||
echo ${{ env.MINOR }} | ||
- name: Major version | ||
if: contains(github.event.head_commit.message, 'major') || ${{ github.event.inputs.version }} == 'major' | ||
run: | | ||
echo "New major version" | ||
echo "MAJOR=$((${{ env.MAJOR }}+1))" >> $GITHUB_ENV | ||
echo "MINOR=0" >> $GITHUB_ENV | ||
echo "PATCH=0" >> $GITHUB_ENV | ||
- name: Minor version | ||
if: contains(github.event.head_commit.message, 'minor') || ${{ github.event.inputs.version }} == 'minor' | ||
run: | | ||
echo "New minor version" | ||
echo "MINOR=$((${{ env.MINOR }}+1))" >> $GITHUB_ENV | ||
echo "PATCH=0" >> $GITHUB_ENV | ||
- name: Patch version | ||
if: contains(github.event.head_commit.message, 'patch')|| ${{ github.event.inputs.version }} == 'patch' | ||
run: | | ||
echo "New patch version" | ||
echo "PATCH=$((${{ env.PATCH }}+1))" >> $GITHUB_ENV | ||
- name: Set 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: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
push: true | ||
tags: | | ||
${{ env.IMAGE_NAME }}:${{ env.MAJOR}}.${{ env.MINOR}}.${{ env.PATCH}} | ||
${{ env.IMAGE_NAME }}:latest | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
- name: Check out the repo | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Create folder if necessary | ||
if: ${{ env.FILE_EXISTS == 'false' }} | ||
run: mkdir -p .github/artifacts | ||
|
||
- name: write_json | ||
id: create-json | ||
uses: jsdaniell/create-json@v1.2.3 | ||
with: | ||
name: "version.json" | ||
json: '{ "major": ${{ env.MAJOR }}, "minor": ${{ env.MINOR }}, "patch": ${{ env.PATCH }} }' | ||
dir: ".github/artifacts/" | ||
|
||
- uses: stefanzweifel/git-auto-commit-action@v5 | ||
with: | ||
commit_message: update version.json (automated) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM node:18 | ||
|
||
WORKDIR /app | ||
COPY package*.json ./ | ||
RUN npm install | ||
COPY . . | ||
EXPOSE 3000 | ||
CMD npm run dev |