fix: fix image_tag variable in continuous deployment (#35) #20
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
name: Continuous Deployment | |
on: | |
push: | |
branches: [main, 'release/**'] | |
workflow_dispatch: | |
env: | |
DH_USERNAME: ${{ secrets.DOCKER_HUB_LOGIN }} | |
DH_TOKEN: ${{ secrets.DOCKER_HUB_PWD }} | |
IMAGE_TAG: ${{ github.ref == 'refs/heads/main' && 'dev' || github.ref }} | |
jobs: | |
build-and-push: | |
name: Build and push Docker images | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js v20 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install dependencies | |
run: | | |
npm install | |
- name: Run semantic release | |
uses: codfish/semantic-release-action@v3 | |
id: semantic | |
with: | |
branches: | | |
[ | |
'release', | |
{ | |
name: 'main', | |
prerelease: 'dev' | |
} | |
] | |
plugins: | | |
[ | |
[ | |
"@semantic-release/commit-analyzer", | |
{ | |
"preset": "angular", | |
"releaseRules": [ | |
{ | |
"type": "refactor", | |
"release": "patch" | |
} | |
] | |
} | |
], | |
[ | |
"@semantic-release/npm", | |
{ | |
"npmPublish": false | |
} | |
], | |
"@semantic-release/release-notes-generator" | |
] | |
- name: Log in to Docker Hub | |
if: steps.semantic.outputs.new-release-published == 'true' | |
run: | | |
echo "$DH_TOKEN" | docker login -u "$DH_USERNAME" --password-stdin | |
- name: Build Docker images | |
if: steps.semantic.outputs.new-release-published == 'true' | |
run: | | |
for APP in webrtc-server loadbalancer; do | |
docker build -f apps/$APP/Dockerfile -t $DH_USERNAME/$APP:$IMAGE_TAG . | |
done | |
- name: Add tags to Docker images and push to Docker Hub | |
if: steps.semantic.outputs.new-release-published == 'true' | |
run: | | |
for APP in webrtc-server loadbalancer; do | |
docker tag $DH_USERNAME/$APP:$IMAGE_TAG $DH_USERNAME/$APP:v${RELEASE_MAJOR}-$IMAGE_TAG | |
docker tag $DH_USERNAME/$APP:$IMAGE_TAG $DH_USERNAME/$APP:v${RELEASE_MAJOR}.${RELEASE_MINOR}-$IMAGE_TAG | |
docker tag $DH_USERNAME/$APP:$IMAGE_TAG $DH_USERNAME/$APP:v${RELEASE_MAJOR}.${RELEASE_MINOR}.${RELEASE_PATCH:0:1}-$IMAGE_TAG | |
docker tag $DH_USERNAME/$APP:$IMAGE_TAG $DH_USERNAME/$APP:v$RELEASE_VERSION | |
docker push $DH_USERNAME/$APP:$IMAGE_TAG | |
docker push $DH_USERNAME/$APP:v$RELEASE_MAJOR-$IMAGE_TAG | |
docker push $DH_USERNAME/$APP:v$RELEASE_MAJOR.$RELEASE_MINOR-$IMAGE_TAG | |
docker push $DH_USERNAME/$APP:v$RELEASE_MAJOR.$RELEASE_MINOR.${RELEASE_PATCH:0:1}-$IMAGE_TAG | |
docker push $DH_USERNAME/$APP:v$RELEASE_VERSION | |
done |