Optimize dockerifle #9
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: Main workflow | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
release: | |
types: | |
- published | |
jobs: | |
lint_test_build: | |
name: Lint, test and build | |
if: github.event_name == 'push' || github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Enable corepack | |
run: corepack enable | |
- uses: actions/setup-node@v4 | |
env: | |
yarn: 4.4.0 | |
with: | |
node-version: 22 | |
cache: 'yarn' | |
- name: Install dependencies | |
run: yarn install | |
- name: Lint | |
run: yarn run lint | |
- name: Test | |
env: | |
ROUTE_PREFIX: /upload | |
LOGGER_LEVEL: error | |
run: yarn run test | |
- name: build | |
run: yarn run build | |
push_latest_dockerhub: | |
name: Push image with latest tag to DockerHub | |
if: github.event_name == 'push' | |
runs-on: ubuntu-latest | |
needs: [lint_test_build] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Login to DockerHub | |
env: | |
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }} | |
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
run: docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_ACCESS_TOKEN | |
- name: Build and tag Docker image | |
env: | |
USER: ${{ secrets.DOCKER_HUB_USER }} | |
REPOSITORY: aws-upload-service | |
TAG: latest | |
run: docker build -t $USER/$REPOSITORY:$TAG . | |
- name: Push Docker image | |
env: | |
USER: ${{ secrets.DOCKER_HUB_USER }} | |
REPOSITORY: aws-upload-service | |
TAG: latest | |
run: docker push $USER/$REPOSITORY:$TAG | |
push_release_dockerhub: | |
name: Push image with release version tag to DockerHub | |
if: github.event_name == 'release' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Set tag variable | |
id: version | |
run: echo ::set-output name=tag::${GITHUB_REF#"refs/tags/"} | |
- name: Login to DockerHub | |
env: | |
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }} | |
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
run: docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_ACCESS_TOKEN | |
- name: Build and tag Docker image | |
env: | |
USER: ${{ secrets.DOCKER_HUB_USER }} | |
REPOSITORY: aws-upload-service | |
TAG: ${{ steps.version.outputs.tag }} | |
run: docker build -t $USER/$REPOSITORY:$TAG . | |
- name: Push Docker image | |
env: | |
USER: ${{ secrets.DOCKER_HUB_USER }} | |
REPOSITORY: aws-upload-service | |
TAG: ${{ steps.version.outputs.tag }} | |
run: docker push $USER/$REPOSITORY:$TAG |